trentrichardson / jQuery-Impromptu

An extention to help provide a more pleasant way to spontaneously prompt a user for input.
http://trentrichardson.com/Impromptu/
MIT License
327 stars 144 forks source link

Pattern validation #75

Open hanspeter1 opened 8 years ago

hanspeter1 commented 8 years ago

Is there a way to use the HTML5 input pattern validation? The submit function is called before the native HTML5 input pattern validation is executed.

This should be possible because Impromptu use a form-element.

Example:

var html = '<div class="form-group">' +
     '<label for="firstName">' + i18n.t("first_name") + '</label>' +
     '<div class="input-group">' +
     '<input type="text" id="firstName" class="form-control" pattern="[A-za-z\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00df]{2,}[ -]{0,1}[A-Za-z\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00df]{2,}|[A-za-z\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00df]{2,}" required>' +
     '<span class="input-group-addon">*</span>' +
     '</div>' +
     '</div>' +
     '<div class="form-group">' +
     '<label for="lastName">' + i18n.t("last_name") + '</label>' +
     '<div class="input-group">' +
     '<input type="text" pattern="[A-za-z\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00df]{2,}[ -]{0,1}[A-Za-z\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00df]{2,}|[A-za-z\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00df]{2,}" id="lastName" class="form-control" value="' + rowData[2] + '" required>' +
     '<span class="input-group-addon">*</span>' +
     '</div>' +
     '</div>' +
     '<div class="form-group">' +
     '<label for="emailAddress">' + i18n.t("email_address") + '</label>' +
     '<input type="email" id="emailAddress" class="form-control" value="' + rowData[3] + '" required>' +
     '</div>' +

 var buttons = {};
 buttons[i18n.t("yes")] = true;
 buttons[i18n.t("no")] = false;
 $.prompt({
      state0: {
      title: "Mod user"
      html: html,
      buttons: buttons,
     submit: function (e, v, m, f) {

    }
 }
});