AnsweredAssumed Answered

Form field validation handler issue

Question asked by afielden on Jan 25, 2019
Latest reply on Jan 30, 2019 by afielden

I'm hoping someone here can help out with this problem, because I've done everything as per the book, to use a Javascript function to validate a form field. Here's what I've done:

 

Altered the share-config-custom.xml file, as follows:

 

<forms>

  <dependencies>
    <js src="js/date-range-validator.js" />
  </dependencies>

<form>

  <appearance>

    <field id="myfield:dfc-start-date">
      <constraint-handlers>
        <constraint type="MANDATORY" validation-handler="myspace.forms.validation.checkDateRangeValidity" event="keyup"/>
        </constraint-handlers>
    </field>

   ...

</form>  

</forms>

 

Created a date-range-validator.js file, which I placed in src/main/assembly/web/js

 

 

if (typeof fbs == "undefined" || !fbs) {
  var fbs = {};
}

 

myspace.forms.validation.checkDateRangeValidity = function checkDateRangeValidity(field, args, event, form, silent, message) {
  var valid = true;

  alert('Checked date ' + field);

return valid;
}

 

However, when the form is displayed I get an exception because "myspace" isn't defined, so it looks like my validator code isn't being loaded. I've tried placing the Javascript file in a variety of locations within the project, but the problem still persists.

Outcomes