1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-09 00:06:55 +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:
Ryan Cramer
2017-01-27 14:03:28 -05:00
parent 279f65ec65
commit 2becc0cbba

View File

@@ -660,6 +660,25 @@ abstract class Inputfield extends WireData implements Module {
return $this->setAttribute($key, $value); 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 * Get all attributes specified for this Inputfield
* *