I want to check existence of "Name", "Email" input field, but I can't find the method(or function) in parsleyjs.org...
This is my simple-form and parsley code:
<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= render 'devise/shared/error_messages', object: f.object %>
<div class="form-inputs">
<%= f.input :name, required: true, autofocus: true%>
<%= f.input :email, required: true %>
<%= f.input :password, required: true, placeholder: "min. 6 characters",
input_html: {"parsley-minlength" => 6, "error-container" =>"#errorBlock"} %>
<%= f.input :password_confirmation, required: true,
input_html: {"parsley-equalto" => "#user_password"} %>
<%= f.collection_select :role, User::ROLES, :to_s, :humanize %>
</div>
<div class="form-actions">
<%= f.button :submit, "회원 가입" %>
</div>
<% end %>
<%= render "devise/shared/links" %>
<script>
$("#new_user").parsley({trigger: "keyup",
errors: {
errorsWrapper: '<div></div>',
errorTemplate: '<span></span>'
}
});
</script>
If I understand correctly your question looking at the comments, it seems that you want to leverage Parsley validation to check in your database if email or name is already taken and display a Parsley error accordingly.
To achieve that, you'll need to use Parsley Remote plugin, and its documentation here: http://parsleyjs.org/doc/index.html#remote
You'll need to work on your APIs to be able to check backend if these fields values already exist in database, and than integrate parsley.remote.js on top of that.
Best
Related
I'm trying to add Mapbox autofill to my address bar on rails, for mapbox autofill to work I need to have autocomplete="street-address in an input field.
I'm using simple_form_form and I can't figure out how to add autocomplete attribute. Here is my form:
<%= simple_form_for #lock do |f| %>
<div class="form_wrapper">
<div class="form_div">
<%= f.input :name %>
<%= f.input :description %>
<mapbox-address-autofill>
<%= f.input :address, :autocomplete => "street-address" %>
</mapbox-address-autofill>
<%= f.input :photo, as: :file, label: "Link to picture" %>
<%= f.input :special_content %>
<%= f.button :submit, :class => "btn btn-primary" %>
<% end %>
any ideas on how to make the autocomplete attribute work?
Use input_html and pass the additional options like class etc.
<%= f.input :address, input_html: { :autocomplete => "street-address"} %>
I am trying to let users RELIST 'gigs' that they have previously posted by duplicating the old one and saving it with a new ID. At the moment everything duplicates fine and can be saved but I need one of the fields (datetime) to be blank as it is vital that they manually set this. I do not know how to set this as nil/blank from the controller.
Relist link:
<%= link_to t('gigs.show.relist'), gig_relist_path(:gig_id => #gig.id), class: 'gig-edit-dash' %>
Gig controller:
def relist
#oldgig = Gig.find(params[:gig_id])
#gig = #oldgig.dup
end
Form:
<div class="create-form">
<%= simple_form_for #gig do |form| %>
<div class="create-title">
<%= form.input :title, label: t('gig.title'), placeholder: t('placeholder.title') %></div>
<div class="create-location">
<%= form.input :location, label: t('gig.location'), placeholder: t('placeholder.location') %></div>
<div class="create-genre">
<ul></ul>
<%= form.label :genres %>
<%= select_tag "choose_genres", options_from_collection_for_select(Genre.all, 'id', 'name',#gig.genres.map{ |j| j.id }), :multiple => true %> </div>
<div class="create-description">
<%= form.input :description, as: :text, label: t('gig.description'), placeholder: t('placeholder.description') %></div>
<div class="create-date">
<%= form.input :date, label: t('gig.date'), placeholder: t('placeholder.date') %></div>
<div class="create-salary">
<div class="salary-input">
<p class="salary-title"> <%= t('gig.salary') %> </p>
<%= form.input :salary_currency, label: false,
collection: ["€", "£", "$" ], prompt: "Choose one" %>
<%= form.input :salary, label: false, placeholder: t('placeholder.salary') %>
</div>
</div>
Setting the default value to nil/blank in the form doesn't work as a value is being passed.
#gig.date = nil
doesn't work either, this sets the time to the current time.
Oh dear, I just figured this out about 2 minutes after posting the question. I'll leave the answer rather than deleting the post just in case someone else finds it useful.
I set #gig.date = nil in the controller after #gig = #oldgig.dup
Then added , :include_blank => true to the form field in the view.
The reasoning is pretty self explanatory.
I have the following simple_form in my rails app:
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title center">Add New Customer</h3>
</div>
<div class="panel-body">
<%= simple_form_for(#customer, html: {class:'form-horizontal'}, wrapper: :horizontal_form) do |f| %>
<%= f.input :first_name, input_html: {class:'form-control'} %>
<%= f.input :last_name, input_html: {class:'form-control'} %>
<%= f.input :phone_number, as: :tel, input_html: {class:'form-control'} %>
<%= f.input :email_address, as: :email, input_html: {class:'form-control'} %>
<%= f.input :address, input_html: {class:'form-control'} %>
<%= f.input :city, input_html: {class:'form-control'} %>
<%= f.input :postal_code, input_html: {class:'form-control'} %>
<%= f.input :customer_type, collection: ["Retail", "Contractor", "Dealer"], input_html: {class:'form-control'}, prompt: "Select Customer Type" %>
<br />
<%= f.button :submit, "Create Customer", class: "col-md-3 bump-right" %>
<% end %>
</div>
</div>
As you can see, I'm using bootstrap styling on the form elements. When I submit the form, I want the following to happen:
Validate email
Validate phone number
Require all fields
As it stands now, when I submit the form, none of the above three happen. Looking through the docs for simple_form (https://github.com/plataformatec/simple_form) I can't discern what I need to do to achieve my end result. I have tried adding f.error fields for each input but that does not seem to do anything.
There is this 2 year old question: simple_form & bootstrap validations not working - but this is foreign to me and given the 2.5 year old versions I'm sure something has changed.
If anyone has any ideas, or can help me demystify the docs I would be grateful.
Use validations in the models (specifically the customer model) which would happen before the data is saved to the database. See the docs here.
Example:
class Person < ActiveRecord::Base
validates :name, presence: true
end
Person.create(name: "John Doe").valid? # => true
Person.create(name: nil).valid? # => false
I have Rails Devise Bootstrap and Simple Form.
My devise registration/sign-up form is in a bootstrap modal. It is a simple form.
When I click on the register link (from my navbar) on my root url, the form works fine. When I navigate to another page and click that link, the simple form fields are blank. The form boxes are there to fill in, but the text above them that describe the field, are missing.
Any ideas? Thank you
This is my form:
<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= f.error_notification %>
<div class="form-inputs" style="padding-left:15%; text-align:left;">
<%= f.input :first_name, required: true, autofocus: true %>
<%= f.input :last_name, required: true, autofocus: true %>
<%= f.input :email, required: true, autofocus: true %>
<%= f.input :password, required: true %>
<%= f.input :password_confirmation, required: true %>
</div>
<div class="form-actions" style="padding-left:15%; padding-top:5%; text-align:left;">
<%= f.button :submit, "Register" %><% end %>
</div>
You should add above each "f.input .." field a "f.label :insert_field_name_here", and it should work.
Really strange, but that text was formatted white in the sub pages. Not sure why, but mystery solved.
On this edit page screen I've set up a "Current Password" field required to edit the user information (to change my name for example) but for some reason that particular current password field is not showing up while all the other input fields do.
I can't figure out why its not showing up?
Thank you!
<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name), html: { :method => :put, class: 'form-horizontal'}) do |f| %>
<%= f.error_notification %>
<%= f.input :name, :label => "Nombre" %>
<%= f.input :email, :label => "Correo Electronico" %>
<%= f.input :password, :label => "Nueva Contraseña", autocomplete: "off" %>
**<%= f.input :password_confirmation, :label => 'Confirmar Contraseña', autocomplete: "off" %>**
<% f.input :current_password, :label => "Contraseña Actual" %>
</br>
<div class= "form-actions">
<%= f.submit "Actualizar Datos", class: "btn btn-primary"%>
</div>
<% end %>
You forgot to add the = in the ERB tab. It won't echo to the page without that. It should look like this:
<%= f.input :current_password, :label => "Contraseña Actual" %>
Keep in mind, statements whose values you do not want to show on the page should omit the equals (=) sign. Examples of those statements would be things like <% if ... %>, <% #some_var.each do .... %> etc.
Values you do wish to appear on the page, such as your input line, should have the equals sign.