Setting an Options list drop down value dynamically
Posted: 2023-10-06 16:36
I have a speed_distance_units field in a sessions table, set with an options list to one of three different values. The exact same field and options are set for each user in a rider table, so I can display charts, reports etc. in the units they prefer. When they create a new session record, I'd like to set this field in the session record automatically to the preference they set in the rider record.
I know how to do this with a regular html table select widget with javascript, but the option list select elements are being set by appgini to use some fancier code:
I suspect that fact is stopping my fairly simple javascript from working:
I've tried variations on the code above, including not using jQuery with the same result.
As I wrote this question, I discovered that the value of the drop down had changed, but the value displayed in the widget had not! When I click on the widget and it drops down, the selection set by javascript is highlighted. But when I click elsewhere to remove the focus, the drop down continues to display the top item:
Any help will be greatly appreciated!
BTW, I know there are other ways to manage user unit preferences, including saving them all in the same units and displaying their preference on the various user interfaces. However that seemed difficult in appgini and still have the units displayed in the table view what they prefer.
I know how to do this with a regular html table select widget with javascript, but the option list select elements are being set by appgini to use some fancier code:
Code: Select all
<script>jQuery(function() {
jQuery("#speed_distance_units")
.addClass('option_list')
.select2({
minimumResultsForSearch: 5,
sortResults: AppGini.sortSelect2ByRelevence
});
})</script>
Code: Select all
$j(function(){
$j('#speed_distance_units').val('Knots');
});
As I wrote this question, I discovered that the value of the drop down had changed, but the value displayed in the widget had not! When I click on the widget and it drops down, the selection set by javascript is highlighted. But when I click elsewhere to remove the focus, the drop down continues to display the top item:
Any help will be greatly appreciated!
BTW, I know there are other ways to manage user unit preferences, including saving them all in the same units and displaying their preference on the various user interfaces. However that seemed difficult in appgini and still have the units displayed in the table view what they prefer.