mirror of
https://github.com/processwire/processwire.git
synced 2025-08-08 15:57:01 +02:00
Add an val() method to the Inputfield class for consistency with jQuery. This method is a shortcut for getting or setting the value attribute of Inputfield objects
This commit is contained in:
@@ -660,6 +660,25 @@ abstract class Inputfield extends WireData implements Module {
|
||||
return $this->setAttribute($key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut for getting or setting “value” attribute
|
||||
*
|
||||
* When setting a value, it returns $this (for fluent interface).
|
||||
*
|
||||
* ~~~~~
|
||||
* $value = $inputfield->val(); * // Getting
|
||||
* $inputfield->val('foo'); * // Setting
|
||||
* ~~~~~
|
||||
*
|
||||
* @param string|null $value
|
||||
* @return string|int|float|array|object|Wire|WireData|WireArray|Inputfield
|
||||
*
|
||||
*/
|
||||
public function val($value = null) {
|
||||
if($value === null) return $this->getAttribute('value');
|
||||
return $this->setAttribute('value', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all attributes specified for this Inputfield
|
||||
*
|
||||
|
Reference in New Issue
Block a user