Skip to content Skip to sidebar Skip to footer

How To Show Different Message On Required And Invalid?

can you please tell me how to show different message on required and invalid ?In other word .make a form from json using plugin .In that there are some required parameter .and s

Solution 1:

As you may read from the official angular-schema-form documentation

Per default all error messages comes from the schema validator tv4, this might or might not work for you. If you supply a validationMessage property in the form definition, and if its value is a string that will be used instead on any validation error.

If you need more fine grained control you can supply an object instead with keys matching the error codes of tv4. See tv4.errorCodes

Ex.

{
  key: "address.street",
  validationMessage: {
    tv4.errorCodes.STRING_LENGTH_SHORT: "Address is too short, man.",
    "default": "Just write a proper address, will you?"   //Special catch all error message
  }
}

You can also set a global validationMessage in formDefaults see Global Options.

So for more error messages, visit this link


Solution 2:

Here is a great blog article that should answer your question: http://www.thebhwgroup.com/blog/2014/08/designing-html-forms-angularjs-part-1/

In particular, check out part 3 "Validation Messages and Styling".

From the article,

<span class="validation-message" ng-show="contactForm.firstName.$error.maxlength">Max length 20</span>

Where the ng-form is named contactForm and the element in question is named firstName. This puts the form on the scope and you can then traverse that to get the errors, and show an error message specifically for each error.


Post a Comment for "How To Show Different Message On Required And Invalid?"