Read only / Disabled form field

I’d like to create a custom ‘ReadOnly’ validator for my models whereby an attribute can be marked as read only (In certain scenarios or by conditions).

The validator would be able to negate any changes to the model, but more so, any form fields relating to a read only attribute would be set to ‘disabled’.

This approach would keep the logic where I think it belongs, in the model.

/**
 * Dummy validator so we can make gui fields read only 
 */
class ReadOnlyValidator extends Validator {
	const script = <<<'JS'
	var inputName = attribute.input;
	jQuery(inputName).prop('disabled', true);
JS;

	/**
	 * {@inheritdoc}
	 */
	protected function validateValue($value)
	{
		return null;
	}

	/**
	 * {@inheritdoc}
	 */
	public function clientValidateAttribute($model, $attribute, $view)
	{
		return self::script;
	}
}

The above code does the trick, but sadly the code is only called after the field has been exited and runs the js validation code. I suppose I could call the form validation code at document.ready… but does anyone have any other suggestions ?

Thanks.