1

Well, I need to add options to a select field with Javascript. I do that with $(...).append(...), the problem is that I get a "Invalid" message. I think it's because the new option's value is not in the available options.

My question is then: Can I add a wildcard to the options? or bypass the validation for this field?

Any better idea?

Thanks!

1 Answer 1

1

Your best option would be to create a custom field type. That's quite a bit of work, though.

Failing that, you could add an extra "Other" option to the select field, and create a separate text field to hold the "free form" option.

Caveats

Craft isn't able to automatically validate the association between two fields. In other words, there's no such thing as "if the user selects the 'other' option, then she must also complete the 'Other' field".

If this is a must-have, you could implement some front-end validation, by injecting custom JavaScript into the Control Panel. Once again, a plugin is the best way to go here, but you may also be able to piggy-back on something like craft-cpjs, by Lindsey Diloreto.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.