mercredi 25 février 2015

Rails custom field_with_errors Proc

I have some markup as follows:



<div class="form">
<input type="text" name="user[email]" id="user_email" data-validate="true">
<label data-content="Your email"></label>
</div>


I am currently using client_side_validations to check and edit the markup to:



<div class="form">
<input type="text" name="user[email]" id="user_email" data-validate="true">
<label data-content="Your email"></label>
<span class="input-error" data-error-id="1">EMAIL IS EMPTY</span>
</div>


If, however, the user were to still submit the form somehow I would need to replicate the same behaviour from Rails' ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| method. All I need to do is add a <span> tag, as above (the id isn't needed via Proc), to the end of the parent in which the <input> tag is contained.


How can I achieve this via Proc?


Aucun commentaire:

Enregistrer un commentaire