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

Question

Question

field validation (max value) ignored with formula calculation

asked on January 23, 2018 • Show version history

Hi everyone,

I have a constraint that a maximum of 10 days are allowed for employees to travel for work. I have 2 date/time fields that are compared to come up with total days.

I am using a formula to calculate this total and calling it Consecutive Days. It is a hidden & read only field. I am using a CSS class to hide it.

When there is a date in both departure AND return fields, then the hidden field is shown. I am using jQuery to assign a max value of 10 to the Consecutive Days field.

//set max concesutive days
  new function(){
    $(".consecDays input").attr("max", '10');
  };
//make visible consecutive days when departure & return dates populated  
  $('.consecDays').change(function(){
    if (($('.depDateTimeClass input').val().length !== 0) && ($('.retDateTimeClass input').val().length !== 0)){
    $('.consecDays').removeClass('hide');
    } else {
    $('.consecDays').addClass('hide');
    }
  });

My issue is that I see a number over that is greater than 10 with no validation error message.

Once the Consecutive Days field is visible, if I click on it and then out, the validation error message appears.

I have tried duplicating the click events, but had no luck. I have tried .trigger('updatevalidation')  from this post.

I know that I can perform the validation in jQuery and display the error validation, but I am at a loss of why this way doesn't work. I am probably missing something. What is it?

Thanks for the help in advance :)

0 0

Answer

SELECTED ANSWER
replied on January 23, 2018 • Show version history

Try triggering the parsley validation instead. For example,

$('.targetFields input').parsley().validate();

Additionally, setting it as read-only complicates things. If you're hiding it anyway, I would remove the read-only attribute to avoid those complications.

1 0

Replies

replied on January 23, 2018 • Show version history

Good tip on the read-only. I changed the jQuery to set it to read-only AFTER it is shown. I used your line of code so I'll give you credit on the answer. It won't work without it. The validation works and it stays read-only! Beautiful.

Thanks Jason!

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

Sign in to reply to this post.