I am using the playframework 2.0 with scala and I am facing many problem with the @select template. So what I have is a @select field as part of a Form (the Form shouldn't be interesting here):
@select(
Form("<variable of select 1>"),
options = options(<call of function which returns a list>),
'_default -> "--- stupid select templates ---",
'_error -> Form.globalError
)
now i have another select. Important about this one is - I want to fill it from a function, which gets the actual value of the first @select as parameter.
@select(
Form("<other name of variable>"),
options = options(<function(<variable of select 1>)>),
'_default -> "--- stupid select templates ---",
'_error -> Form.globalError
)
So what i actually need is some kind of "onchange" envent for the @select fields. Another problem is, that the playframework can't read the "'_default" value of the @select (when I set a default value and try to use it in a Form, it gets counted as None)
NOTE: both @selects are on the same html site and both belong to the same form
Does someone know a workaround here? or possible examples?
One example where the
default
works for me, also if owner is filled the owner will be visible instead of default value.But I do not think that
onchange
is possible from server side templates. You will need to do this with javascript / jQuery.@adis answer is correct. If you want to dynamically populate a dropdown based on the value that was just chosen, you have two choices:
1) Trigger a form submit when the first select takes place and use that to populate the next drop down or 2) Use Javascript and possibly an ajax call to do this dynamically
The first option is pretty ugly since it requires you to reload and re-populate the form. This can cause other validation related issues, not to mention that it's a very 90's solution, so I wouldn't recommend it.
Something like this should help... Populate one dropdown based on selection in another