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

Question

Question

Check/Validate a Number for a Field in a Table

asked on June 12, 2020

The user provides info in a table:

That validation field is filled in via a stored procedure that queries Laserfiche:

If the record (Doc ID + Doc No + Revision) are in the system, it returns a "1", otherwise, it returns a -1 or 0. This has been made available but not required. Now I'd like for the user to receive a message when the number is NOT a 1. Any ideas on how I could go about that? Here's what I've tried so far:

$(document).ready(function(){
//Validation is now required - Must show a 1!
  $("input[id^=Field49(1)]").change(function () { 
    if ($(this).val() != '1'{
      alert('Validation = 1 is now required. The document number format must match exactly as it is in Laserfiche.');
    }
  });
});  //close document.ready

Thanks!

0 0

Answer

SELECTED ANSWER
replied on June 12, 2020 Show version history

Validation on read-only fields can be a bit tricky because it is usually triggered when the field loses focus and you're not usually giving focus to a read only field. However, it would still run the validation before submitting the form.

If you really wanted to force it, you could attach a change event handler that forces it to run the validation immediately.

UPDATE: It looks like front end validation is actually ignored on read only fields, so you'd need to do something else to ensure the validation.

Option 1 - require validation on read only fields

$(document).ready(function(){
  // force validation of read only fields
  $('form.cf-form').parsley({excluded: Parsley.options.excluded + ', .lf-no-validate'});  
  
  // trigger validation when field changes
  $('.myTable').on('change','.myColumn input',function(){
    $(this).parsley().validate();
  });
});

Option 2 - use a custom validator to validate one of the editable fields against the "validation" column instead (this would be a bit more complicated).

1 0

Replies

replied on June 12, 2020

Why not just try using the built in field validation? If it is a number field you could set the valid range to only equal 1, or if it is a text field you could use regex.

Since the column is so narrow, you might want to use CSS to make the error message wider or something like that, but it would be better than an alert which can be blocked by the browser.

The benefit of the built-in validation is that it would also prevent them from submitting the form.

2 0
replied on June 12, 2020

Brilliant! I knew there'd be an easier way. Thank you!

 

0 0
replied on June 12, 2020

Hmmm, still have an issue. I put:

But don't know why the highlighted items below are not errorring out:

0 0
SELECTED ANSWER
replied on June 12, 2020 Show version history

Validation on read-only fields can be a bit tricky because it is usually triggered when the field loses focus and you're not usually giving focus to a read only field. However, it would still run the validation before submitting the form.

If you really wanted to force it, you could attach a change event handler that forces it to run the validation immediately.

UPDATE: It looks like front end validation is actually ignored on read only fields, so you'd need to do something else to ensure the validation.

Option 1 - require validation on read only fields

$(document).ready(function(){
  // force validation of read only fields
  $('form.cf-form').parsley({excluded: Parsley.options.excluded + ', .lf-no-validate'});  
  
  // trigger validation when field changes
  $('.myTable').on('change','.myColumn input',function(){
    $(this).parsley().validate();
  });
});

Option 2 - use a custom validator to validate one of the editable fields against the "validation" column instead (this would be a bit more complicated).

1 0
replied on June 15, 2020

Thank you so much for following up with this answer!

0 0
replied on June 18, 2020

So, small issue. A user puts data in that table by mistake (they wanted to put their data in the table below). They delete it, however, there's still a validation going on that causes the user to not be able to continue:

Here's what I thought would solve the issue, but it doesn't.

$(document).ready(function(){

//Force validation of read-only fields
  $('form.cf-form').parsley({excluded: Parsley.options.excluded + ', .lf-no-validate'});  
  
//Trigger validation when field changes
  $('.affectedDocs').on('change','.count input',function(){
    $(this).parsley().validate();

    if (($('.docIDDesc input').val() == '') && ($('.docNo input').val() == '') && ($('.revision input').val() == '')){
        $('.count input').val('');
    }
  });

});  //close document.ready

What am I doing wrong?

0 0
replied on June 18, 2020

That's odd, the lookup should run again when the value is cleared out, which should update the value of the validation field.

Do you get any errors in the console?

 

You wouldn't necessarily want to use $('.count input').val('') anyway because that would affect the entire column, not just that row.

0 0
replied on June 23, 2020

Here's what I see in the console:

SCRIPT7016: SCRIPT7016: Use of XMLHttpRequest with the synchronous flag set to true is deprecated due to its impact on user-perceived site performance.

0 0
replied on June 23, 2020

That's a fairly common warning/error so it shouldn't be related.

I'm a bit stumped. If there's no related errors in the console, then there shouldn't be anything "breaking" with your code.

To troubleshoot and help narrow things down, I'd add the following to the form to monitor when your lookup events are actually firing.

$(document).ready(function () {
  $(document).on("lookupstarted", function (event) {
        console.log('lookup started: ' + event.triggerId);
    }
  });

  $(document).on("lookupcomplete", function (event) {
        console.log('lookup completed: ' + event.triggerId);
  });
});

 

1 0
replied on June 24, 2020

@████████, thanks so much for all help in trying to solve this issue. The validation does work when it is changed. I think it just a bug that it doesn't "clear". That said, I have found an acceptable workaround as it really doesn't happen too often.

I set up a field rule that will show message in maroon when the validation doesn't let the user continue due to a validation field that won't clear:

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

Sign in to reply to this post.