Grails noSelection property in the select tag over rides the value

孤街醉人 提交于 2019-12-12 01:43:32

问题


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:


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 --']" />


来源:https://stackoverflow.com/questions/38585489/grails-noselection-property-in-the-select-tag-over-rides-the-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!