Laegnur Posted November 2, 2022 Share Posted November 2, 2022 Hello. In a client website, they have a form with all the Spanish provinces as Select options. The client want that when there is an address saved on client's profile, the form preloads it. The province is saved as text string on profile. So, I explode it, and get and an array with all the address parts. Now I'm trying to set the Select's selected value to the option with same name as the province part of the address but I'm getting an error: "Method InputfieldSelect::addOptionAttributes does not exist or is not callable in this context" What I'm doing wrong? $field = $modules->get("InputfieldSelect"); $field->label = "Provincia"; $field->attr('id+name','provincia'); $field->addOptions([ "Alava" => "Álava/Araba", "Albacete" => "Albacete", "Alicante" => "Alicante", ..... ]); $field->required = 1; $field->addOptionAttributes($direccion[3], array("selected")); Link to comment Share on other sites More sharing options...
iank Posted November 2, 2022 Share Posted November 2, 2022 @Laegnur Are you running an older version of PW by any chance? InputfieldSelect::addOptionAttributes was only added around version 3.105. The above code works for me, (PW Version 3.200) if I use: $field->addOptionAttributes('Alicante', array("selected" => "selected")); Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now