Skip to content

Instantly share code, notes, and snippets.

@ryantbrown
Created April 16, 2015 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryantbrown/4f9d9c145e8d9d2b843d to your computer and use it in GitHub Desktop.
Save ryantbrown/4f9d9c145e8d9d2b843d to your computer and use it in GitHub Desktop.
Semantic UI - Auto Validation via Data Attrs
// form validation loaded from config
$('.ui.form').each(function(index){
var config = $(this).data('config');
if(config !== undefined) {
$(this).prepend('<div class="ui icon error message" id="form-errors"></div>');
var settings = APP.config.validation;
config.split('.').forEach(function(el, i, arr){
settings = settings[el];
});
$('#form-'+settings.id).form(
settings.rules,
$.extend({}, APP.config.forms.global.options, settings.options)
);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment