2

I have created a safecracker form that has some fields that with show / hide depending on the previous filed selection. For example:

 <label
    for="med">Are you currently taking any prescribed medication?:</label>
    <label><input
    type="radio" name="med" value="Yes"{checked} id="med2"  />&nbsp;Yes</label><label><input
    type="radio" name="med" value="No"{checked} id="med1"  />&nbsp;No</label>

    <br>{clear}<br>
<div id="med">
     <label for="medication" class="required">Please detail:</label>    {field:medication}<br></div>   

This code will show the {field:medication} if the yes radio button is selected. I can't use the normal code provided in the safecracker example as each field option needs to have a different id for the jquery action.

Unfortunately the {checked} code does not save the radio option when the form is saved. I'd appreciate any advice. Thanks

2 Answers 2

1

You could use:

<input type="radio" name="my_field" value="Yes"{if med == 'Yes'}Checked{/if} />
<input type="radio" name="my_field" value="No"{if med == 'No'}Checked{/if} />

If you get problems saving a 'required' field, then try adding hidden inputs:

<input name="my_field" type="hidden" value=""/>
1
  • This helped me today.. Thanks for the reminder :D Commented May 10, 2013 at 16:13
2

This should be a comment rather than an answer but I can post better code examples here. So the example for using custom fields looks like:

  {if radio}
            {options}
                    <label class="checkbox">{option_value}
                            <input type="radio" id="{field_name}" name="{field_name}" value="{option_value}"{checked}>
                    </label>
            {/options}
    {/if}

That includes IDs. Why can't you use that code?

2
  • Does the id on the example not output the same for both values? I need a different id for each value.
    – user579984
    Commented Jan 10, 2013 at 9:08
  • In that case you could do something like id="{field_name}_{option_value}".
    – Tyssen
    Commented Jan 10, 2013 at 20:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.