Grails noSelection property in the select tag over

2019-09-11 11:51发布

I have the select tag below:

            <g:select name="recommendation" from="${recommendation.list()}"
                      optionKey="id" optionValue="recommendation"
                      value="${theAssessment.recommendation}"
                      noSelection="['':'-- Select Assessor Recommendation --']"
                      />

The form works as expected as when the value is null the noSelection is displayed. When I use the select tag to select the data I want to submit, this also works fine as this is persisted in the database. When I then go back to the form the noSelection over rides the value even when the value is not null. I've looked at the docs and I'm using this tag exactly as stated.

1条回答
虎瘦雄心在
2楼-- · 2019-09-11 12:33

You are using optionKey="id" so that the Select value should be assigned as id.

   // I guess your Value should be id here     
       <g:select name="recommendation" from="${recommendation.list()}" optionKey="id" optionValue="recommendation"
                  value="${theAssessment?.recommendation?.id}"
                  noSelection="['':'-- Select Assessor Recommendation --']" />

If above code not work then try this.

       <g:select name="recommendation" from="${recommendation.list()}" 
              value="${theAssessment?.recommendation}"
              noSelection="['':'-- Select Assessor Recommendation --']" />
查看更多
登录 后发表回答