How can I set the selected value of a dropdown using a smarty variable - frontend

I have a list of suppliers and a defaultSupplier assigned to a template, I add the suppliers to a dropdown and iterate through them using a foreach and I try to make the default selected value depending on the defaultSupplier like this:
<select name="supplier_id" id="supplier_id" class="selectpicker" data-live-search="true" data-width="100%" data-show-tick="false">
<option value="" {if $defaultSupplier eq ""}selected="selected"{/if}>-- {"Choose a supplier"|t} --</option>
{foreach $suppliers as $s}
<option value="{$s.supplier_id}" {if ($defaultSupplier == $s.supplier_name)}selected="selected"{/if}>{$s.supplier_name}</option>
{/foreach}
</select>
But it doesn't work, I get the "Choose a supplier" option selected then I have to manually select my supplier from the dropdown

I had to close the page and navigate on it again and it worked

Related

Trying to select item from dropdown box

Trying to select an item from a drop down list using a variable.
I'm able to click the drop down list, I'm able to click on the item with explicit text but not using a variable.
Chrome (v 75.0.3770.142) using Selenium Basic ChromeDriver (v 75.0.3770.140) in Excel (2013) VBA.
it works if i use explicit:
Obj.FindElementByXPath("//option[#label='Z01 - Customer Request - Paid']").Click
but doesn't work if using a string variable:
Obj.FindElementByXPath("//option[#label=SomeStringVariable]").Click
Here's the HTML:
<select id="tickboxreason" name="boxreason" class="emergency-reasons form-control ng-touched ng-dirty ng-valid-parse ng-valid ng-valid-required" ng-model="currentCartConfig.boxreason" ng-options="reason.displayValue for reason in reasonList.emergencyOrderReasons | orderBy:'code' track by reason.code" ng-change="updateRDD()" ng-required="currentCartConfig.emergencyFlag" required="required">
<option value="">Select Reason</option>
<option value="Z01" label="Z01 - Customer Request - Paid">Z01 - Customer Request - Paid</option>
</select>
You have missed the string quotes.Try the below option.
Obj.FindElementByXPath("//option[#label='" & SomeStringVariable & "']").Click
I would go with a faster css attribute = value selector
obj.FindElementByCss("[label='" & variable & "']").click

Group 'input option values' in template variable with 'listbox' type

I would like to apply the grouped text in listbox, looks like this
to
this is listbox in the resources page.
I tried to add the ‘optgroup’ tag into
'manager\templates\default\element\tv\renders\input\listbox-multiple.tpl'
but still not working, the 'optgroup’ tag will be ignored.
I unterstand that I should ‘Adding a Custom TV Input Type’ but the document didn’t include the details about grouping input values.
That is easy ;)
your listbox should contain a #CHUNK yourchunk
In that chunk you can perform nearly everything, that genereates a list, like:
<select name="something" id="something" >
<option value="" selected disabled>choose</option>
<optgroup label="Headline 01">
[[pdoResources? &parents=`0` &where=`{"template:=":40` &sortby=`{"value":"ASC"}` &limit=`40` &tpl=`pdoResourcesFormoption-something` &includeTVs=`some-tv`]]
</optgroup>
<optgroup label="Headline 02">
[[pdoResources? &parents=`0` &where=`{"template:=":41` &sortby=`{"value":"ASC"}` &limit=`40` &tpl=`pdoResourcesFormoption-something` &includeTVs=`some-tv`]]
</optgroup>
<optgroup label="Headline 03">
[[pdoResources? &parents=`0` &where=`{"pagetitle:=":"something"` &sortby=`{"value":"ASC"}` &limit=`40` &tpl=`pdoResourcesFormoption-something` &includeTVs=`some-tv`]]
</optgroup>

how to select a value in combo boxes with geb groovy

i tried to select a value out of a combo box via groovy(geb).
the html code is:
<select id="entity-list-form:statusSearchBtn" name="entity-list-form:statusSearchBtn" size="1" style="width: 200px;">
<option value="">alle</option>
<option value="REGISTERED" selected="selected">Wartet auf Bestätigung</option>
<option value="REJECTED">Registrierung zurückgewiesen</option>
<option value="APPROVED">Registrierung angenommen</option>
<option value="UNSUBSCRIBED">Abgemeldet</option>
</select>
i tried to access these elements via
$("entity-list-form").statusSearchBtn = "alle"
or
$("entity-list-form").statusSearchBtn.value() == "alle"
a different approach was in the page siet to add
statusSearchBtn { $('select[name$="entity-list-form:statusSearchBtn"]') }
and also the case with the name only like entity-list-form. in this caes i tried it like
statusSearchBtn = "alle"
or
statusSearchBtn.value() == "alle"
the last one end without any errors, but didnt change the selected value to "alle".
the former one ended in No such property: statusSearchBtn for class: geb.navigator.EmptyNavigator.
i greatly apprichiate any advice,
I think:
$("select", name : "entity-list-form:statusSearchBtn").value('alle')
$("select", name : "entity-list-form:statusSearchBtn").value() = 'alle'

Author Dropdown Select Field in a SafeCracker Form

Is it possible to have an author dropdown select field in a SafeCracker form, in a similar way to how you can have a Status dropdown select field with the following code?
{status_menu}
<label for="status">Status</label>
<select name="status" id="status">
{select_options}
</select>
{/status_menu}
I've searched the docs and EE forums but can't find anything, but hoping there's a way of doing this.
Thanks for any help,
Ste
Edit:
Thanks to Tyssen's reply below, I've just implemented this solution in a SafeCracker form and it works great. Just one note though - the name should be author_id rather than author. Here's my final code, including a conditional to show the entry's current author:
<label>Author</label>
<select name="author_id">
{exp:query sql="SELECT member_id, screen_name, group_id FROM exp_members ORDER BY screen_name ASC;"}
<option value="{member_id}" {if "{member_id}" == "{author_id}"}selected="selected"{/if}>{screen_name}</option>
{/exp:query}
</select>
Use the query module maybe?
<select name="author">
{exp:query sql="SELECT member_id, screen_name
FROM exp_members
WHERE group_id = X;"
}
<option value="{member_id}">{screen_name}</option>
{/exp:query}

Kohana 3 form select validation

Hay all,
I am trying to validate a select in kohana 3.0 and I am using the necessary rules. However the validation does no "kick in" when the user does not make a selection.
<select id="discipline" name="discipline" >
<option value="0"> -- Select One -- </option>
<option value="-2">Information Technology and Engineering</option>
<option value="4">Business and Training Seminars</option>
</select>
That was my select, now i have applied these rules to the post array before i check for validation errors.
$post = Validate::factory($_POST)
->rule('discipline', 'not_empty')
->rule('discipline', 'numeric');
When I submit the form without making a selection, the form submits and the rules should stop it.
Any ideas ?
Your still putting a value for the first one, as 0. Leave the value as value="". 0 is numeric and considered not empty.
Replace 0 with blank string
Add ->rule('discipline', 'in_array', array(array(-2, 4))); to check that selected discipline is within valid collection.
string empty first option
<select name="fruit" required>
<option value="">select fruit</option>
<option value="banana">banana</option>
</select>
then some css may help
form:invalid button[type="submit"], form:invalid input[type="submit"] {
opacity: 0.5;
cursor: default;
}

Resources