Rails Validation | add class to surrounding <div> -


itemprop = "text">

Railway questions are for default behavior fields for error verification, such as error-style divisions around input fields, such as < / P>

  & lt; Div class = "type-text" id = "pre_negotiation_value_div" & gt; & Lt; Label = "contract_budget_holder" & gt; Budget Holder & lt; / Label & gt; & Lt; Div class = "fieldWithErrors" & gt; & Lt; Input id = "contract_budget_holder" name = "contract [budget_holder]" size = "30" type = "article" value = "" /> & Lt; / Div & gt; & Lt; / Div & gt;  

I'm trying to complete, to enclose the label and input field with the classified div tags, so that they look like the following:

  & Lt; Div class = "type-text fieldwhetherers" id = "pre_negotiation_value_div" & gt; & Lt; Label = "contract_budget_holder" & gt; Budget Holder & lt; / Label & gt; & Lt; Input id = "contract_budget_holder" name = "contract [budget_holder]" size = "30" type = "article" value = "" /> & Lt; / Div & gt;  

Any ideas how to complete this? Can you hook javascript into ActionView :: Base.field_error_proc?

I'm new to the rail, I'm sorry it's super easy!

Thank you for your help.

Jonathan

It's not very easy to do exactly what you want , But if you have ERB:

  & lt; Div id = "pre_negotiation_value_div" class = "type-lesson" & gt; & Lt;% = f.label: name% & gt; & Lt;% = f.text_field: name% & gt; & Lt; / Div & gt;  

You will get HTML like this:

  & lt; Div id = "pre_negotiation_value_div" class = "type-text" & gt; & Lt; Div class = "fieldWithErrors" & gt; For label = "foo_name" & gt; Name & lt; / Label & gt; & Lt; / Div & gt; & Lt; Div class = "fieldWithErrors" & gt; Input id = "foo_name" name = "foo [name]" size = "30" type = "text" value = "" /> & Lt; / Div & gt;  

Where both the label and the text fields are fields, the ether's DID will be around them. Based on how you want to style it, it can be great if it is not enough, then you have to do a custom assistant like this:

Viewer :: Helper :: Formbild DEF labeled_input (method, option = {}, and block) (option [: class] || = "") & lt; & Lt; If the "objectWithErrors" @ object.errors.on (method) ActionView :: Helpers :: InstanceTag.send (: alias_method ,: original_error_wrapping ,: error_wrapping) ActionView :: helper :: instantatge send (: define_method,: error_wrapping, Proc New {| Html_tag, has_error | html_tag}) @ template.concat (@ template.content_tag (: div, @ template.capture (& amp; block) option)) ActionView :: Help: :: InstanceTag.send (: alias_method,: < / Code>

It has been inserted into config / initializers / labeled_input.rb . This is a bunch of ruby ​​meta-foo, but what it does is put the "Fieldwise Authors" class on the external field, it is temporarily error_wrapping to the InstanceTag method Redefines so that the internal label and text_filtered tags do not have a "Fieldwise Arrows" division around them. You use it in the ERB:

  <% f.labeled_input: name ,: id = & gt; "Pre_negotiation_value_div",: class = & gt; "Type-Text"% & gt; & Lt;% = f.label: name% & gt; & Lt;% = f.text_field: name% & gt; & Lt;% end% & gt;  

Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -