
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
bootstrap_validator_rails
Advanced tools
Rails client side validation using BootstrapValidator Plugin: https://github.com/nghuuphuoc/bootstrapvalidator Bootstrap Form as the form builder. https://github.com/bootstrap-ruby/rails-bootstrap-form
##Installation
gem install bootstrap_validator_rails
or add this to your Gemfile
gem 'bootstrap_validator_rails', '~> 1.1.0'
then run
bundle install
##Usage
Add this to your application.js
//= require bootstrapValidator
//or
//= require bootstrapValidator.min
and your application.css
/*= require bootstrapValidator */
/* or */
/*= require bootstrapValidator.min */
In you model
class Product
validates :name, presence: true
validates :price, numericality: {greater_than: 20}
validates :intro, length: {in: 50..200}
validates :terms_of_service, acceptance: {on: :create} # only validates if new_record?
validates :sku, format: {with: /\A[a-zA-Z]+\z/, message: "only allows letters"}
# Thank Brian Cardarella for this: http://reefpoints.dockyard.com/ruby/2011/11/18/convert-ruby-regexp-to-javascript-regex.html
end
In your form
= bv_form_for(@product) do |f|
= f.text_field :name
= f.text_field :price
Please make sure to add the script
$(document).ready(function() {
$('#your_form').bootstrapValidator();
});
Generated HTML
<input id='product_name' name='product[name]' data-bv-notempty='' data-bv-notempty-message='cannot be blank'/>
<input id='product_price' name='product[price]' data-bv-greaterthan-inclusive='false' data-bv-greaterthan-value='20' />
activerecord:
errors:
models:
post:
attributes:
title:
blank: is required
Please see: http://guides.rubyonrails.org/i18n.html#error-message-scopes
Please refer to Bootstrap Form: https://github.com/bootstrap-ruby/rails-bootstrap-forms
Add this to your application.js
//= require bootstrapValidatorRails
And in your HAML/ERB
.my-awesome-form= simple_form_for @post do |f|
= f.input :title
= bv_javascript_for @post
Actually bv_javascript_for
generates script like this
//<![CDATA[
$(document).ready(function() {
bv_form('.bv_form', {"fields":{"post[title]":{"validators":{"notEmpty":{"message":"can't be blank"},"regexp":{"regexp":"^[a-zA-Z]+$","message":"only allows letters"}}},"post[price]":{"validators":{"step":{"message":"should be odd","base":1,"step":2}}},"post[accepted]":{"validators":{"notEmpty":{"message":"should be accepted"}}}}})
});
//]]>
So make sure that you have added bv_form to your form classes
= simple_form_for @post, html: {class: 'bv_form'} do |f|
= f.input :title
<div class="form-group">
<div class="checkbox">
<label>
<input type="checkbox" id="terms">
Check yourself
</label>
</div>
</div>
FAQs
Unknown package
We found that bootstrap_validator_rails demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.