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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

haydeniv’s picture

It might be a while before I get to this but patches are always welcome.

Summit’s picture

Hi,
By selecting other having the same issue.
greetings, Martijn

legolasbo’s picture

Version: 7.x-2.x-dev » 7.x-3.x-dev
Issue summary: View changes

New features will be developed against the 7.x-3.x branch

AaronBauman’s picture

Patches 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

Status: Needs review » Needs work

The last submitted patch, 4: select_or_other-other_optional-1886538-2.x.patch, failed testing.

AaronBauman’s picture

2.x isn't supposed to pass...

AaronBauman’s picture

Status: Needs work » Needs review
legolasbo’s picture

@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?

legolasbo’s picture

Component: CCK / Field API widget » Field widget (non-specific or listed)
Status: Needs review » Needs work
markusd1984’s picture

#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?

diff --git a/select_or_other.info b/select_or_other.info
index 20cc32f..3d2b355 100644
--- a/select_or_other.module
+++ b/select_or_other.module

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).

markusd1984’s picture

issue

Could 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?

markusd1984’s picture

I 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!

Created a custom module so the Other option (select_or_other) is listed after the select/none item and before the existing options (from the other field values).

Making it easier to select 'Other' option (custom entries) being the first option underneath instead of listed above/ontop.
Also better then 'Other' as default since one gets used to selecting underneath in a list, where also existing values are listed.

Other highlighted by CSS + Chosen