2

I'm looking to change a select fields options with the onChange event from another select fields chosen option. Obviously this can be done with js on the frontend as per this post but has anyone done this for the control panel? I imagine it will need to be done via a fieldType plugin, but wondered if anything already exists for this type of functionality before I attempt to build something.

2
  • Do you already have a plugin and fieldType where you want to do this, or do you mean "this one built-in selectField is connected to this other built-in selectField? – fuling Jul 23 '15 at 10:04
  • Could be either. If there is a way to connect select fields in craft already then great where can I find the documentation for it. If not then I would be looking at a plugin to do this. – Lettie Jul 23 '15 at 12:16
2

I would write a custom fieldtype (http://buildwithcraft.com/docs/plugins/field-types) with two selects. Makes sense to make it as one field if they are dependent of eachother.

Just store the field as json (AttributeType::Mixed) and inject your own javascript in the fields getFieldHtml()

1

Instead of building a custom fieldtype, you could just connect two standard dropdown menus with some custom JavaScript. The easiest way to do that would probably be via the Control Panel JS plugin.

Fortunately, the control panel already uses jQuery, so you wouldn't need much JS to tie the two fields together.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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