Developer forum

Forum » Templates » Checked and selected radio buttons and select

Checked and selected radio buttons and select

Thomas Clausen
Reply

Hi

I'm building a custom HTML-template for a form using the Forms (for Datalists) (not sure about the translation), but I can't seem to get radio buttons and selects working correctly.

Because of the layout of the form I can't use the default output method <!--@Field.Control--> instead I want to use the following markup:

<label for="<!--@Field.Systemname-->"><!--@Field.Label--></label>
<!--@LoopStart(FieldOptions)-->
    <label><input type="<!--@Field.Type.ToLower()-->" name="<!--@Field.Systemname-->" id="<!--@Field.Systemname--><!--@FieldOptions.LoopCounter-->" value="<!--@Field.Option.Value-->" /><!--@Field.Option.Text--></label>
<!--@LoopEnd(FieldOptions)-->

 

The only thing missing though is a check for a preselected option, which I can't get working.
I'v tried the following if statements (using radio buttons as example):

<!--@If(Field.Value == Field.Option.Value)-->checked="checked"<!--@EndIf-->
<!--@If(Field.Value != Field.Option.Value)--><!--@Else-->checked="checked"<!--@EndIf-->
<!--@If(Field.Value <> Field.Option.Value)--><!--@Else-->checked="checked"<!--@EndIf-->
<!--@If(Field.Value.Contains(Field.Option.Value))-->checked="checked"<!--@EndIf-->

Hope someone can help me!


Replies

 
Nuno Aguiar
Reply

Hi Thomas,

 

I had some troubles also, but then I made some default form templates for XHTML and HTML5, both table and tableless. I also use a jsvascript file to perform some validations, but you can delete those and make your own.

 

Nuno

 
Thomas Clausen
Reply

Hi Nuno

Thanks for your reply.
I've created a simular file but I'm affraid that it doesn't solve my problem of checking if an option in a select og a specific radio button should be preselected upon load of the page.

Thomas

 
Nuno Aguiar
Reply

Hi Thomas,

 

By using If Statements with the Server.Request tag and the Field.SystemName, you should get that working. Or use Razor to do that.

 

Nuno

 

You must be logged in to post in the forum