[2.0.2] bindFromRequest not working with select

136 views
Skip to first unread message

Ben

unread,
Oct 31, 2012, 11:49:06 PM10/31/12
to play-fr...@googlegroups.com
Hi guys,
So I have an issue with my play/scala atm and was wondering if anyone could help.
So what I have is a configuration page that is allowing you to set the network interface adapter, and then you can submit the form and save the settings.

So i display the list of network interfaces with scala with the following code:

            <select id="networkInterfaces">
                <option value="">First Available</option>
                @for(interface <- networkInterfaces) {
                    @if(interface.Name == configs.last.networkInterfaceName) {
                        <option selected="selected" value="@interface.Name">@interface.DisplayName</option>
                    } else {
                        <option value="@interface.Name">@interface.DisplayName</option>
                    }
                }
            </select>
And my form code:
public static Result newConfiguration() {
        Form<SystemConfiguration> filledForm = configForm.bindFromRequest();
        if (!filledForm.hasErrors()) {
              SystemConfiguration.create(filledForm.get(), session("name"));
        }

}

But my problem is if I load the value as selected, it displays as if it is selected in html and even $('networkInterfaces').val() is correct but if I do not actually select anything manually then for some reason the value passed to the filledForm.get() is the @interface.DisplayName instead of @interface.Name

Have I done something wrong?

James Roper

unread,
Nov 1, 2012, 10:36:00 PM11/1/12
to play-fr...@googlegroups.com
First of all, checkout @helper.select, as it can probably help you here, eg:

@helper.select(form("networkInterfaces"), networkInterfaces.map(i => (i.Name -> i.DisplayName))

Now to solving your problem:

1) Have you checked what gets rendered?  Is what you are expecting in the value field?
2) Have you checked what is going over the wire using browser developer tools (eg, firebug, or the chrome developer console)?

Cheers,

James

Paulo "JCranky" Siqueira

unread,
Nov 5, 2012, 4:25:19 AM11/5/12
to play-fr...@googlegroups.com

Just a guess, but I think your select should have a name attribute.  :-)

[]s,

Paulo "JCranky" Siqueira
http://jcranky.com
http://lojinha.paulosiqueira.com.br

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To view this discussion on the web visit https://groups.google.com/d/msg/play-framework/-/4Yoz4pgtNd0J.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.
Reply all
Reply to author
Forward
0 new messages