readonly

Since: Editor 1.0

Read-only text field.
Please note - this property requires the Editor extension for DataTables.

Description

This field type adds a read only text field that cannot be modified by the end user to the form.

As this field is read only, it will always contain the value that it is set up with the form is displayed (that is the default, fields.def for the create form, and the data value for the edit form). If you wish to set a different value, you can do so using the API - val() or field().val() methods. Read only is in the sense that the end user cannot modify the value only and as such this should not be considered to be a client-side security measure.

Note that the disable() and field().disable() methods can be used to mimic this field type's behaviour with the other field types. The readonly is designed to be used with fields that are only ever read only and will not accept user input.

Options

This field type supports the following options (in addition to the default options):

attr

Set HTML attributes on the input element. This is an object of attribute name / value pairs that are applied to the input element for the field. This makes it possible to set attributes such as maxlength and required.

Methods

This field type does not support any additional methods over the default methods.

Examples

Basic initialisation:

editor.add({
	type: 'readonly',
	label: 'Read only field',
	name: 'counter',
	def: '1'
});

Setting a value on show:

var counter = 1;

editor.add({
	type: 'readonly',
	label: 'Read only field',
	name: 'counter',
	def: counter
});

editor.on('open', function () {
	editor.field('counter').val(counter++);
});

// Note, this could also be achieved using `def` as a function