Extending RadioField for readonly logic


#1

Hi,

I’m having a hard time extending the RadioField with some readonly logic.

This code, working for the other fields, is not working:

class MyFieldField extends RadioField {
  public function readonly() {
   // Some code here to determine true or false
    return true;
  }
}

However, this code is working:

class MyFieldField extends RadioField {
  public $readonly = true;
}

Of course I can’t put any advanced logic in the later approach. Also this is not consistent with the way other fields work.
Is this a bug with the RadioField or am I missing something here?

Thank you,
Georg


#2

The readonly stuff in the Radio field is handled in the input method, to overwrite this, you would have to modify this method. You can create a readonly method and then call this within the input method.

So instead of :slight_smile:

  if($this->readonly) {
      $input->attr('disabled', true);      
    }

change it to

  if($this->readonly()) {
      $input->attr('disabled', true);      
    }

#3

Thank you, this was it! :slight_smile: