Implement legacy way of using a negative size to set a textbox readonly, but still getting an input widget instead of just text

This commit is contained in:
Nathan Gray 2013-02-05 14:42:23 +00:00
parent 0828e3db75
commit 3da0cb09ac
2 changed files with 38 additions and 1 deletions

View File

@ -42,6 +42,31 @@ class etemplate_widget_textbox extends etemplate_widget
}
}
/**
* Parse and set extra attributes from xml in template object
*
* Reimplemented to handle legacy read-only by setting size < 0
*
* @param string|XMLReader $xml
* @return etemplate_widget_textbox current object or clone, if any attribute was set
*/
public function set_attrs($xml)
{
parent::set_attrs($xml);
// Legacy handling only
// A negative size triggered the HTML readonly attibute, but not etemplate readonly,
// so you got an input element, but it was not editable.
if ($this->attrs['size'] < 0)
{
$this->setElementAttribute($this->id, 'size', abs($this->attrs['size']));
self::$request->readonlys[$this->id] = false;
$this->setElementAttribute($this->id, 'readonly', true);
trigger_error("Using a negative size to set textbox readonly. " .$this, E_USER_DEPRECATED);
}
return $this;
}
/**
* Validate input
*
@ -129,4 +154,4 @@ class etemplate_widget_textbox extends etemplate_widget
}
}
}
etemplate_widget::registerWidget('etemplate_widget_textbox', array('textbox','int','integer','float','passwd','hidden','colorpicker'));
etemplate_widget::registerWidget('etemplate_widget_textbox', array('textbox','int','integer','float','passwd','hidden','colorpicker'));

View File

@ -102,6 +102,9 @@ var et2_textbox = et2_inputWidget.extend({
if(this.options.blur) {
this.set_blur(this.options.blur);
}
if(this.options.readonly) {
this.set_readonly(true);
}
this.input.addClass("et2_textbox");
this.setDOMNode(this.input[0]);
@ -138,6 +141,15 @@ var et2_textbox = et2_inputWidget.extend({
}
},
/**
* Set HTML readonly attribute.
* Do not confuse this with etemplate readonly, which would use et_textbox_ro instead
* @param _readonly Boolean
*/
set_readonly: function(_readonly) {
this.input.attr("readonly", _readonly);
},
set_blur: function(_value) {
if(_value) {
this.input.attr("placeholder", _value + ""); // HTML5