Skip to content

Utility package to facilitate consistent user experience for required fields on forms.

License

Notifications You must be signed in to change notification settings

brewhk/required

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

required

Utility package to facilitate consistent user experience for required fields on forms.

Usage

Add the package via Atmosphere.

meteor add brewhk:required

brewhk:required provides the Required object with two functions - checkClass and highlightByClass

If you want to check, within the current template, whether all input fields with the class brew__required are all filled in, run Required.checkClass

checkClass

Checks that all elements within the template instance with the specified class are filled in, otherwise return an array of all elements which are not filled-in.

Parameter Type Mandatory Notes
className string Yes The name of the class to check for
templateInstance Object No A Meteor template instance to check in. If none is provided, the entire document is checked
callback Function No An optional callback which will be passed `true` if all elements validate, or `false` and the array of failed elements as the first and second parameters, respectively.
highlightByClass

Checks that all elements within the template instance with the specified class are filled in, otherwise add a class to those which are not filled in.

Parameter Type Mandatory Notes
className string Yes The name of the class to check for
errorClass string Yes The name of the error class to add if the required field is not filled in
templateInstance Object No A Meteor template instance to check in. If none is provided, the entire document is checked

Example

// Inside template helper or events handler
let thisTemplate = Template.instance();
Required.checkClass('brew__required', thisTemplate, function (success) {
    if(success) {
      // All fields are filled in
  } else {
        // Some / All fields are missing
      thisTemplate.$('.errorMsg').eq(0).append('Please ensure all fields are completed.');

      // Optionally, add the `errorInput` class to any required elements which are not filled in
      Required.highlightByClass('brew__required', 'errorInput', thisTemplate);
  }
});

About

Utility package to facilitate consistent user experience for required fields on forms.

Resources

License

Stars

Watchers

Forks

Packages

No packages published