Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I would like "Other" to be the default value for my select_or_other field, and I would like the textfield to be empty when the form is rendered.
This is currently impossible.
Comments
Comment #1
haydeniv CreditAttribution: haydeniv commentedIt might be a while before I get to this but patches are always welcome.
Comment #2
Summit CreditAttribution: Summit commentedHi,
By selecting other having the same issue.
greetings, Martijn
Comment #3
legolasboNew features will be developed against the 7.x-3.x branch
Comment #4
AaronBaumanPatches attached for 3.x and 2.x
Inside (same for both):
- config option on field widget "other optional", to optionally make the "other" text field non-required
- same option added to select_or_other FAPI element
Comment #6
AaronBauman2.x isn't supposed to pass...
Comment #7
AaronBaumanComment #8
legolasbo@aaronbauman,
Patch looks good, but in order to ensure quality and prevent regressions I want every new feature and every bugfix to be covered by tests. Could you please add test coverage so I can commit the patch?
Comment #9
legolasboComment #10
markusd1984 CreditAttribution: markusd1984 commented#4 for 3.x didn't work for me (for latest 7.x-3.0-alpha3+1-dev), btw. I tried to manually apply the patch line by line and was confused to find a reference to the .info file without any line changes, should that not refer to the .module instead?
Basically with the option "Other text value is optional" enabled even after having saved it I can't set "other" as Default value with empty textfield.
This feature would certainly make it so much easier for list with regular new title entries to have it preselected (while also avoiding the workaround to have set an empty space or something else, only for people to not enter a title/value and able to save it without having actually entered a custom new title/value).
Comment #11
markusd1984 CreditAttribution: markusd1984 commentedCould the issue be related to HTML5 required attribute issue https://www.drupal.org/project/select_or_other/issues/2481127 ?
That this prevents the 'other' textfield to be empty?
Comment #12
markusd1984 CreditAttribution: markusd1984 commentedI think this is conflicting with
$.fn.prop ? $other_input.prop('required', true) : $other_input.attr('required', true)
in in select_or_other.js ?When I comment this out I can select the "select" option and without value in the text field it will allow saving but the state is not saved as afterwards it lists "-None-" again.
FYI - I added a modification to provide an optional checkbox to let the user decide whether to add the value or not https://www.drupal.org/project/select_or_other/issues/3155490
I think I changed my mind to not using setting the "select" other as default but the "-Select" option instead because that way the user get's used to select lists to realise they can select either creating a custom value or select an existing one.
(Instead of always having a custom value open and lazy people might only use that instead and risk creating duplicate similar entries just because of typos or not realise they can select that after it's added in the list).
I would prefer though to show the "select other" under neath "-select" so it's an easier logical choice in drop-down to either select the custom or existing value. probably need to modify "Other button" always on top
UPDATE: Managed to add myself Other option always on top but between select and options in lists!