-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dropdown Boxes Do Not Show Default Selection #8
Comments
I am not seeing this problem on MS Windows, SketchUp 21.1.332, with the latest commit Thomas has made. When you report issues, please follow the template: ie: platform, SketchUp version, repository version*. * We have to give you a pass on the repository version as Thomas has been making changes without changing the version in the "extension.json" file. The SketchUp version is important as the Chromium framework is updated every few major releases. |
I'm sorry, this is not correct. Using The This is normal as it should be. The coder can test for the empty return and know then that the end user skipped that control.
... meaning the What is probably confusing in that Vue doc example you linked to, is that it is using a variable name "selected" which is also a HTML attribute identifier. This only appears to give it more meaning then intended. The name of that variable (actually an object property) could be anything, ... "desired", "wanted", "highlighted", ... whatever , it's only an name binding an HTML element value to a JS object property value. |
Apologies, yes this is was on SU2020 [20.2.172] Chromium 64.0.3282.119 and Windows 10. I have some machines on which I cannot upgrade on every release due to production reasons. But I shall compare with the latest SU and repository version. I do note, however, that I am passing the exact same arguments I was sending to UI.inputbox to HtmlUI.inputbox (I have written myself a little toggle to flip from one to the other) and that means when I provide defaults to the old inputbox then I can start with the dropdown in a selected state (seeing the default value) and I am not getting the same result in HtmlUI.inputbox. Will check again on newest SU. |
Okay I have tested on SU2017, SU2018, SU2020 and SU2021 (all latest releases.) I do not have any issues with default values for dropdowns or listboxes or textboxes or checkboxes being properly set. |
Quick update: I just found some use case where I do get the default selection in the dropdown, but I still have another case where I don't - so most likely it has something to do with the parameters that are being passed in. Bear with me while I track this down... |
Ok, make sure that you have the same html file as in the repo.
I think I only tested strings. It would be smart to test all data types. |
Ok, I think I found the issue. It's more of a bug exploit in the old inputbox - and not a bug in the new one. I am of course referring to the usage of UI.inputbox with four arguments which is the only way to create dropdowns in classic UI.inputbox. I had a case in my code where the option strings being passed into inputbox as a pipe-separated string contained some trailing spaces as padding. Interestingly, old UI.inputbox was so forgiving it would still match a non-padded default value string to a padded option string and would then still start with the dropdown in selected state. The new HtmlUI.inputbox is no longer as forgiving - which is fine. I cleared the trailing spaces and now starting the dropdowns in selected state with the desired default value works as before. |
Yes we definitely do not want to bring the various bugs in Add to this that the bugs manifest differently on Mac then on Windows. So annoying! It has been like this since I started with SketchUp 13 years ago, and no amount of complaining has been good enough to get it fixed. Padding is/was an attempt to workaround the several bugs in the prompt rendering widths and the edit control widths. (The main bug in The spacing between prompt column and input column is also 0. (This causes coders to try to test their prompts for max length and add 2 spaces to the longest one.) It would have been better had they just fixed the layout problems and right stripped whitespace from prompts, defaults and options. Then all the complaints would end.
My memory is tickled by a vague idea that in one of the release cycles the workaround padding of option values was acknowledged and internally right stripped so that they could match defaults. But the lack of proper documentation has resulted in a bug report (even though I think the options whitespace right-strip was intentional) ... Issue 588: inputbox returns string with trailing spaces truncated, in which I said ...
I think that the scenario where the default would be whitespace padded was overlooked. Mr. Gerard showed a valid example where existing object name properties (ie, for definitions, materials, etc.) might be used for default values and may be right padded. This causes another workaround where the default must be stripped, and then the return This scenario is likely rare, but informing coders of whitespace stripping for options (and not for defaults) in the Now, all that said, ... the This led me to find several design errors in the code. One is that only when using the advanced hash argument is the default checked to be sure that it exists in the options list. (see Another is that |
Hah, glad to hear I am not the only one who resorted to string padding trying to control the width of the old UI.inputbox. Of course, undocumented value stripping should not be brought across into the new inputbox. What might be considered is to have a log/console warning along the lines of "Warning: trailing whitespace detected in options string. This might lead to unexpected behaviour in default selection". This could help avoid some confusion for other coders who will also likely be converting existing code by pointing it at the new HtmlUI.inputbox. |
I'm not sure about the warning. Most experienced rubyists think they are noise.
You do understand that this is not a common library, but an example for a custom library for other coders to wrap in their own namespaces and modify to their own tastes ? |
Of course. Just thinking about everybody stepping into the same pitfall... This this github thread now being here might also be enough. |
I'll accept a PR that emits a warning if it's a trivial change. Otherwise my understanding is that we can close this? |
It was due to whitespace padding in option values from code using the native
I'll go along with a warning ... as long as it is conditional upon This MAY only be needed for using the ie ... where a warning message class ArgumentParser
PAD_WARNING ||= 'Warning:(HtmlUI::inputbox) Trailing whitespace detected'<<
" in options string.\n"<<'This may cause default value not to match and'<<
" control will render without initial selection.\n"
And then replace the if args.size > 2 && args[2].is_a?(Array)
# NOTE: Empty string options map to empty arrays:
arguments[:list] = args[2].map { |object| object.to_s.split('|') }
title_index += 1
# Conditionally warn if any option has trailing whitespace values:
if $VERBOSE || Sketchup::debug_mode?
# Check for trailing whitespace padded options:
trailing_whitespace = /\S+\s+\z/i
# (arguments[:list] is an array of options arrays)
warn(PAD_WARNING) if arguments[:list].any? { |list|
next false if list.empty?
list.any? { |opt| opt =~ trailing_whitespace }
}
end
end |
A warning may help some people who wish to migrate from old to new inputbox. Otherwise this thread here will also help them. Ok to close. |
I can do the PR but will need to refresh my repository branching skills.
A Migration wiki would be benefit here, rather than relying upon users perusing closed issues. |
The dropdown input controls generally work as intended. However, dropdown controls always start out showing an empty selection. The user has to manually operate the dropdown and make a selection to see the current value.
The expected behavior (to mimic the original UI.inputbox) would be that the first value of the input array should be displayed as the dialog opens.
The obvious solution would be to control this in the
<option>
tag by adding something along the lines of<option v-for="option in input.options" **v-bind:selected="$index === 0"**>.
However, it appears this is not possible in vue if v-model is being used, as vue will always override this depending on model data.
Vue documentation indicates the default selection needs to happen somewhere inside here:
However up to now I have not been able to determine exactly how to set the first element of the input array in this data structure so it gets displayed when the dialog opens.
The text was updated successfully, but these errors were encountered: