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

Question

Question

Limit Maximum Value of Read-only Number Filed Based on Another read Only Number Filed

asked on May 10, 2022

Dear All

I am new Java Script , I would like to Limit the maximum value of Number filed which is Read only based on another filed , I got one Java Script from Laserfiche answers which is working , but when I Make the filed read-only the java script is not working is it anyway I can accomplish that below is my code

$(document).ready(function(){
  // whenever max value changes
  $('.maxattendees input').on('change',function(){
    // get max from field
    var max = $(this).val();
    
    // get number1 field
    var number1 = $('.attendees input');
    
    // check if max populated
    if (max != '') {
      // set number1 max value
      number1.attr('max',max);
    }
    else {
      // remove restriction if max blank
      number1.removeAttr('max');
    }
    
    // if not blank, revalidate
    if(number1.val() != '') number1.parsley().validate();
  });
});

 

 

0 0

Answer

SELECTED ANSWER
replied on May 12, 2022 Show version history

Hi Shameer,

I tried again with maxattendees also read-only and filled by formula, and noticed that the script actually works when value of table column changes, but doesn't work on the initial form load.

An easy workaround would be manually trigger 'change' event on the maxattendees field after initial form load. For example, added following script after Line 22

var event = new Event('change');
var element = document.querySelector('.maxattendees input');
element.dispatchEvent(event);

Hope it helps.

0 0

Replies

replied on May 11, 2022

Hi Shameer,

The script seems still works for me when the field with attendees class is read-only and the field with maxattendees is editable. Could you elaborate on how it doesn't work on your side?

0 0
replied on May 11, 2022

Hi ziyan Chen

In my Case , I need both field as read only , now if I make attendees Editable and maxttendees read only the script works , Maxattendees pull the value from lookup fileds , while attendees filed using the formula from a total value of table column , when I make both readonly the script is not working .I tried to using #Field_ID (Id value taken as q_ID , expample I make #Field21 when my filed value was q21) but that was also came as no luck , 

0 0
SELECTED ANSWER
replied on May 12, 2022 Show version history

Hi Shameer,

I tried again with maxattendees also read-only and filled by formula, and noticed that the script actually works when value of table column changes, but doesn't work on the initial form load.

An easy workaround would be manually trigger 'change' event on the maxattendees field after initial form load. For example, added following script after Line 22

var event = new Event('change');
var element = document.querySelector('.maxattendees input');
element.dispatchEvent(event);

Hope it helps.

0 0
replied on May 14, 2022

Hi Ziyan Chen

That works perfectly , Thank you .

 

 

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

Sign in to reply to this post.