Skip to content
This repository was archived by the owner on Jan 31, 2019. It is now read-only.

Working with Formtastic Bootstrap

justin808 edited this page Feb 6, 2012 · 3 revisions

To support the Formtastic-Bootstrap form builder for Formtastic, include the following javascript snippet when displaying the form:

ClientSideValidations.formBuilders["FormtasticBootstrap::FormBuilder"] = {
  add: function (element, settings, message) {
    if (element.data('valid') !== false) {
      element.addClass('error').data('valid', false);
      var $parent = element.closest('.input');
      $parent.parent().addClass('error');
      $('<span/>').addClass('help-inline').text(message).appendTo($parent);
    } else {
      element.parent().find('span.help-inline').text(message);
    }
  },
  remove: function (element, settings) {
    var $parent = element.closest('.input');
    $parent.parent().removeClass('error');
    $parent.find('span.help-inline').remove();
    element.data("valid", true);
    element.removeClass('error');
  }
};

This would add the missing callbacks for showing and hiding form errors.

  • Note: This code relies on the presence of jQuery. If you're using another framework (or none at all), you may need to make some small changes here.
Clone this wiki locally