ruby on rails - Adding a background image or an image tag to Formtastic radio buttons with a collection -
I have this form field, where a user inputs their credit card data:
& lt;% = form.input: credit_card_type ,: as = & gt; : Radio ,: collection = & gt; User.credit_card_types% & gt;User.credit_card_types look like this:
def self.credit_card_types {'visa' => Visa, 'MasterCard' = & gt; MASTER_CARD, 'American Express' = & gt; AMERICAN_EXPRESS} and
give me the following HTML:
& lt; Li id = "user_credit_card_type_input" class = "radio optional" & gt; & Lt; Fieldset & gt; & Lt; Legend class = "label" & gt; & Lt; Label & gt; Tipo D Stalves & lt; / Labels & gt; & Lt; / Narrative & gt; & Lt; Ol & gt; & Lt; Li & gt; & Lt; Label = "user_credit_card_type_1" & gt; For & lt; Input type = "radio" value = "1" name = "user [credit_card_type]" id = "user_credit_card_type_1" & gt; Master Card & lt; / Labels & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; Label = "user_credit_card_type_0" & gt; For & lt; Input type = "radio" value = "0" name = "user [credit_card_type]" id = "user_credit_card_type_0" & gt; Visa & lt; / Labels & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; Label = "user_credit_card_type_2" & gt; & Lt; Input type = "radio" value = "2" name = "user [credit_card_type]" id = "user_credit_card_type_2" & gt; American Express and Lieutenant; / Labels & gt; & Lt; / Li & gt; & Lt; / Ol & gt; & Lt; / Fieldset & gt; & Lt; / Li & gt;
Given this, I have a question, how can I add a specific background image to each radio button label? I can not do it with CSS because labels have no ID and I can not (or I do not know how to) put one then I tried to add an image_tag but it was saved from HTML. any suggestion?
Formstastic can be customized for your needs should be there. Add a line like this:
Formtastic :: SemanticFormHelper.builder = SemanticCustomFormbuilder
Then create a file named semantic_custom_form_builder.rb in your lib directory. >
Class Semantic Consoleformbilder & lt; FormTastic :: SemanticFormbuilder def cicloon_special_radio_button_input # You can use your custom definitions in your own forms, such as:
= Form.input: credit_card_type ,: as = & gt; : Cicloon_special_radio_button% & gt;
Comments
Post a Comment