You are viewing limited content. For full access, please sign in.

Question

Question

Set maximum value of field with JavaScript?

asked on May 5, 2017

Hi,

I have a formula that is defining a currency value in <Field A>. I want to use that value to set the maximum currency value of <Collection.Field B>. As values are added to <Collection.Field B> the value in <Field A> is reduced, with the final result being that the value of <Field A>=0, and the total available funds have been allocated.

My equation is working, and I know I will have to set the maximum value in JavaScript, but I'm not sure how to. I'm running 10.1 and there isn't a Min/Max setting in field properties for currency. I could just switch it to a number type if that would help.

Thanks.

0 0

Replies

replied on May 10, 2017

Here is an example of setting max value on fieldB (with class 'fieldB') based on fieldA (with class 'fieldA'):

$(document).ready(function(){
  $('.fieldA input').change(updateMaxValue);
  function updateMaxValue() {
    $('.fieldB input').attr('max', $('.fieldA input').val());
  }
});

 

1 0
replied on May 10, 2017

Thank you Rui,

That does set the max value. I didn't know about the "max" keyword.

I will need to do a little more work to make it function exactly the way I want.

I was hoping that the validation would not allow the invalid input to pass back to FieldA.

In other words, if FieldA = 1000, and the user inputs 1100 into FieldB, it still changes the value of FieldA to -100. And alerts that the value of FieldB must 100.

 

0 0
replied on May 10, 2017

There is no way to hold off the formula calculation; you can change the formula to custom function for calculating fieldA value.

I tried to implement based on your idea but got some issues: when add a new row, the max for field in new row should be updated while the existing field should not (otherwise validation would fail). What if the user changed the exiting field value? There won't be error on the field but the sum of values may exceed.

I think one solution is not to set max on fields, but set validation for sum of fields. How do you feel about it?

1 0
replied on May 11, 2017

I think what I'm going to do is to abandon the idea of validation, and use the "text below" FieldB to dynamically display the current remaining balance, just to help them keep track of where they are at with current allocation.

I really appreciate your time on this.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.