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

Question

Question

Show error message and disable submit button based on specific/static list of data

asked on June 15, 2020 Show version history

Hello, I'm still new to both Laserfiche and Javascript so any help is much appreciated.  I have code sort of working that I sourced from Ege Ersoz but it isn't easy to scale if the data in my list ever changes and I need it to work for validating multiple values.

 

Our end user wants to disable the submit button on a form and display a message if a 5-digit number doesn't specifically match a static list of about 2500+ numbers.

 

What I have works for a single digit, but I need to have about 2500 more 5-digit numbers (which I also have in an excel list) and I want to display text that says something like "This number isn't valid" if a 5-digit number entered does not match my list. 

I'm still researching how to accomplish this, but I'm reaching out to see if someone has a better solution or more appropriate code for my needs.

$(document).ready(function() {
  
  $('.Submit').hide();
  
  $('#q17 input').on('blur', function() {
    if ($('#q17 input').val() == "01234") {

      $('.Submit').show();
    } else {
      alert('It appears you are not eligible');
      $('.Submit').hide();
    }
  });
  
});

Edited: I have the pop up message working, just curious how to get multiple data validation.

0 0

Replies

replied on June 15, 2020

Do you have Forms Professional and Lookups? If so, I'd probably do something like this:

  1. Store the numbers in a SQL database table
  2. Connect that table to the form as a Data Source
  3. Create a field on the form called "Validation" or something like that and give it a custom CSS class of "inputValidation" or whatever makes sense to you.
  4. Make the field Read Only and use Field Rules to hide it always
  5. Create a lookup for the validation field (when Input = Column, populate Validation Field with Column)
  6. Assign a custom validator to your input field that require the lookup to be blank.

 

$(document).ready(function(){
  // assign custom validator
  customValidators();
  
  // trigger validation of input field when validation field changes
  $('.inputValidation input').on('change',function(){
    $('#Field37').parsley().validate();
  });
});

function customValidators(){
  // validator to check if value is not found by lookup
  window.Parsley.addValidator('eligiblevalue', {
    validateString: function(value) {
      return value != $('.inputValidation input').val();
    },
    messages: {
      en: 'It appears you are not eligible.'
    }
  });
  
  // assign validator to source field
  $('#Field37').attr('data-parsley-eligiblevalue','');
}

Now, when the user enters something that matches an entry in the table, it will populate the validation field, trigger the validation on the input field, and display an error directly under the field. The added bonus is that the validation error will prevent submission without having to hide the button.

Note that with the pop-up message and showing/hiding the button, there's a still a chance that something could still slip through and get submitted when it shouldn't have.

 

A database is probably the best option in case you need to change the values later, but you could use a similar approach even without that if you don't have lookups.

1 0
replied on June 16, 2020 Show version history

A coworker and I found a solution, similar to what Jason Smith suggested but with using LF built in Data Management > Lookup Table tool.  I created a Lookup Table using the excel file. Then created a Query off of that Lookup Table.  Made a hidden field that if the user fills in the 5-digit number, the Query will autofill a hidden field.  If that hidden field is blank it hides the submit button and alerts the user with a message.

(#q59 is the hidden field)

$(document).ready(function() {
  
  $('.Submit').hide();
  
  $('#q59 input').on('change', function() {
    if ($('#q59 input').val() == "") {
             alert('Your message here.');
      $('.Submit').hide();
    } else {
      $('.Submit').show();
    }
  });
  
});

 

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

Sign in to reply to this post.