This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

lucas.sanner54070
lucas.sanner54070

In my form I have a dropdown list which need to have some of its options disabled according to the state of the model.

fields.yaml

     status:
         tab: Manage
         label: Status
         span: left
         type: dropdown

The model:

 public function getStatusOptions()
 {       
     return array('pending' => 'Pending',
                  'refused' => 'Refused',
                  'pending_subscription' => 'Pending subscription',
                  'canceled' => 'Canceled',
                  'member' => 'Member',
                  'pending_renewal' => 'Pending renewal',
                  'revoked' => 'Revoked');
 } 

 public function filterFields($fields, $context = null)
 { 
     $fields->status; // <= Don't know how to use it...     
 }

1) Is it possible to disable some options through the getStatusOptions array ?

2) Is it possible to disable some options through the filterFields function and how ?

Last updated

mjauvin
mjauvin

Should be possible to REMOVE options in both methods, not DISABLE... what exactly do you want to do?

lucas.sanner54070
lucas.sanner54070

Well, removing options is a bit too radical. These statuses (pending, refused etc...) are part of a workflow and the user has to see them all, even though some of them are not selectable. So, to me disabling options is the best way to go.

mjauvin
mjauvin

I don't think that's possible with October currently. There is no way to pass attributes to the options.

It can be done with custom JavaScript, though.

Last updated

lucas.sanner54070
lucas.sanner54070

Thanks for clarifying.
Yes, Javascript is the solution.
Ex:

$('#Form-field-Member-status option[value="revoked"]').prop('disabled', true);
// Refreshes the dropdown list.
$('#Form-field-Member-status').select2().trigger('change');
Andrey Palamarchuk
Andrey Palamarchuk

lucas.sanner54070 said:

Thanks for clarifying.
Yes, Javascript is the solution.
Ex:

$('#Form-field-Member-status option[value="revoked"]').prop('disabled', true); // Refreshes the dropdown list. $('#Form-field-Member-status').select2().trigger('change');

Thanks. It's a good temporary solution

1-6 of 6

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.