当前位置: 动力学知识库 > 问答 > 编程问答 >

html - play framework Multiple forms with checkbox fields with the same name attribute

问题描述:

I have a form which could have multiple smaller forms inside it. All the smaller forms have the same type of fields. I have two checkbox fields in each of the smaller forms with the name= "timeOfTheDay". One checkbox has value "morning". The other one has value "evening". Now for all the forms the name "timeOfTheDay" is same, So only one value out of all the forms is getting selected. Only one selection could be done at a time in overall form for this field.

Also I cant change the name of this field as, in Play Model, I am using the same model for all the forms, Which does mapping with name.

Please suggest some solution for this.

My main model:

public class Details {

//Default For all customers

public String timeOfTheDay;

public Integer cost;

public String day;

//Customized details for each customers

public CustomForm customDetails[];

}

CustomForm is:

public class CustomForm {

public String timeOfTheDay;

public Integer cost;

}

defaultForm template:

//these are the params i am sending while rendering the file from controllers

@(id: Long, detailsForm : Form[models.Settings.Details], isEdit: Boolean)

<div class="col-md-2 text-left min-size-label removePadding">

<span>Day</span>

</div>

<div class="col-md-10 removePaddingLeft">

@input(detailsForm("day"), 'class -> "form-control col-xs-12 formField ")

</div>

<div class="col-md-2 text-left min-size-label removePadding">

<span>Cost</span>

</div>

<div class="col-md-10 removePaddingLeft">

@input(detailsForm("cost"), 'class -> "form-control col-xs-12 formField ")

</div>

<div class="col-md-10 text-left min-size-label removePadding">

<span><b>Time of the day</b></span>

</div>

<div class="col-sm-12">

@inputRadioGroup(

detailsForm("timeOfTheDay"),

options(enums.timeOfDayEnum.timeOfDayMap()),

'name -> "timeOfTheDay",

'class -> "timeOfTheDay"

)

</div>

CustomForm template:

@(id: Long, customDetailsForm : Form[models.Settings.CustomForm], isEdit: Boolean)

<div class="col-md-2 text-left min-size-label removePadding">

<span>Cost</span>

</div>

<div class="col-md-10 removePaddingLeft">

@input(customDetailsForm("cost"), 'class -> "form-control col-xs-12 formField ")

</div>

<div class="col-md-10 text-left min-size-label removePadding">

<span><b>Time of the day</b></span>

</div>

//options are fetched from enums

<div class="col-sm-12">

@inputRadioGroup(

customDetailsForm("timeOfTheDay"),

options(enums.timeOfDayEnum.timeOfDayMap()),

'name -> "timeOfTheDay",

'class -> "timeOfTheDay"

)

</div>

Both the forms have the same timeOfTheDay named radio button field. Also I can have many customForm in a single page. Then they will obviously have the same name as they are using the same model. So how do i make selection for each of those forms individually.

分享给朋友:
您可能感兴趣的文章:
随机阅读: