Created
June 21, 2012 09:42
-
-
Save jugyo/2964874 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # config/initializers/client_side_validations.rb | |
| ... | |
| module SimpleForm | |
| class FormBuilder | |
| def self.client_side_form_settings(options, form_helper) | |
| {type: 'SimpleForm::FormBuilder'} | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // app/assets/javascripts/rails.validations.simple_form.js | |
| /* | |
| Client Side Validations - SimpleForm - v1.5.0.beta.3 | |
| https://github.com/dockyard/client_side_validations-simple_form | |
| Copyright (c) 2012 DockYard, LLC | |
| Licensed under the MIT license | |
| http://www.opensource.org/licenses/mit-license.php | |
| */ | |
| (function() { | |
| ClientSideValidations.formBuilders['SimpleForm::FormBuilder'] = { | |
| add: function(element, settings, message) { | |
| var errorElement, wrapper; | |
| if (element.data('valid') !== false) { | |
| wrapper = element.closest('.control-group'); | |
| wrapper.addClass('error'); | |
| $('.controls .help-inline', wrapper).remove(); | |
| errorElement = $("<span/>", { | |
| "class": 'help-inline', | |
| text: message | |
| }); | |
| var helpBlock = $('.controls .help-block', wrapper); | |
| if (helpBlock.size() == 0) { | |
| return $('.controls', wrapper).append(errorElement); | |
| } else { | |
| helpBlock.before(errorElement); | |
| } | |
| } else { | |
| return element.parent().find("span.help-inline").text(message); | |
| } | |
| }, | |
| remove: function(element, settings) { | |
| var errorElement, wrapper; | |
| wrapper = element.closest('.control-group.error'); | |
| wrapper.removeClass('error'); | |
| errorElement = wrapper.find("span.help-inline"); | |
| return errorElement.remove(); | |
| } | |
| }; | |
| }).call(this); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # config/initializers/simple_form.rb | |
| SimpleForm.setup do |config| | |
| ... | |
| config.wrappers :bootstrap, :tag => 'div', :class => 'control-group', :error_class => 'error' do |b| | |
| b.use :html5 | |
| b.use :placeholder | |
| b.use :label | |
| b.wrapper :tag => 'div', :class => 'controls' do |ba| | |
| ba.use :input | |
| ba.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' } | |
| ba.use :hint, :wrap_with => { :tag => 'p', :class => 'help-block' } | |
| end | |
| end | |
| ... | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment