Sep 10, 2013

Bootstrap: Automatically add asterisk symbol to detected 'required' form input field

$('input').each(function(){
   if($(this).is('[required=required]')){
    if ($(this).is('[noAsterisk]')){
    return null;
   } else {
       $(this).closest(".YourClassName").children("label").append('<font style="color:red;position:absolute;" > *</font>');
   }
   }
});

* javascript above require jQuery
with the code:
if ($(this).is('[noAsterisk]')){
     return null;
}
allow you to add exception with 'noAsterisk', where you don't require asterisk as there had 'required' html tag appended.

No comments:

Post a Comment

Hey, thank you for spending time leaving some thoughts, that would be really helpful as encouragement for us to write more quality articles! Thank you!