mirror of
https://github.com/processwire/processwire.git
synced 2025-08-12 17:54:44 +02:00
Add feature request for InputfieldSubmit to support independent button text from button value per processwire/processwire-issues#877
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
/**
|
||||
* An Inputfield for handling "submit" buttons
|
||||
*
|
||||
* ProcessWire 3.x, Copyright 2016 by Ryan Cramer
|
||||
* ProcessWire 3.x, Copyright 2019 by Ryan Cramer
|
||||
* https://processwire.com
|
||||
* License: MPL 2.0
|
||||
*
|
||||
@@ -12,6 +12,11 @@
|
||||
* @property bool $small Whether or not button should be small, where supported (default=false).
|
||||
* @property string $dropdownInputName Name of input to receive selected dropdown value (default='_action_value') #pw-internal
|
||||
* @property bool $dropdownSubmit Selected dropdown value becomes submit value? (default=true) #pw-internal
|
||||
* @property string $html Button inner HTML label (default='') @since 3.0.134
|
||||
* @property string $text Button inner TEXT label, if $html not provided. (default='') @since 3.0.134
|
||||
* @property string $value Button value attribute and inner TEXT label, if $text it provided (default='Submit')
|
||||
* @property string $textClass Class applied to span for inner html/text, omitted if blank (default='ui-button-text') @since 3.0.134
|
||||
* @property-read string|false $submitValue Value that was submitted if clicked (default=false) @since 3.0.134
|
||||
*
|
||||
*/
|
||||
class InputfieldSubmit extends Inputfield {
|
||||
@@ -50,9 +55,13 @@ class InputfieldSubmit extends Inputfield {
|
||||
$this->attr('type', 'submit');
|
||||
$this->attr('name', 'submit');
|
||||
$this->attr('value', $this->_('Submit')); // Standard submit button label
|
||||
$this->set('submitValue', false); // becomes string after processInput
|
||||
$this->attr('class', 'ui-button ui-widget ui-state-default ui-corner-all');
|
||||
$this->set('textClass', 'ui-button-text');
|
||||
$this->skipLabel = Inputfield::skipLabelBlank;
|
||||
$this->set('small', false);
|
||||
$this->set('html', '');
|
||||
$this->set('text', '');
|
||||
|
||||
// name of 'hidden' input that will receive the clicked dropdown item value
|
||||
$this->set('dropdownInputName', '_action_value');
|
||||
@@ -160,10 +169,18 @@ class InputfieldSubmit extends Inputfield {
|
||||
*/
|
||||
public function ___render() {
|
||||
$attrs = $this->getAttributesString();
|
||||
$icon = $this->icon ? $this->sanitizer->name($this->icon) : '';
|
||||
$icon = $icon ? "<i class='fa fa-$icon'></i> " : '';
|
||||
$value = $this->entityEncode($this->attr('value'));
|
||||
$out = "<button $attrs><span class='ui-button-text'>$icon$value</span></button>";
|
||||
$icon = $this->icon ? $this->wire('sanitizer')->name($this->icon) : '';
|
||||
$icon = $icon ? wireIconMarkup($icon) . ' ' : '';
|
||||
$buttonText = $this->getSetting('html'); // option for non-encoded button text
|
||||
if(empty($buttonText)) {
|
||||
$buttonText = $this->getSetting('text');
|
||||
if(empty($buttonText)) $buttonText = $this->attr('value');
|
||||
$buttonText = $this->entityEncode($buttonText);
|
||||
}
|
||||
$buttonText = $icon . $buttonText;
|
||||
$textClass = $this->wire('sanitizer')->entities($this->getSetting('textClass'));
|
||||
if(!empty($textClass)) $buttonText = "<span class='$textClass'>$buttonText</span>";
|
||||
$out = "<button $attrs>$buttonText</button>";
|
||||
if($this->getSetting('small')) $out = "<small>$out</small>";
|
||||
if(count($this->dropdownItems)) $out .= $this->renderDropdown();
|
||||
return $out;
|
||||
@@ -235,7 +252,31 @@ class InputfieldSubmit extends Inputfield {
|
||||
*
|
||||
*/
|
||||
public function ___processInput(WireInputData $input) {
|
||||
// submit buttons don't need to process any input
|
||||
|
||||
$this->submitValue = '';
|
||||
$name = $this->attr('name');
|
||||
$value = $input->$name;
|
||||
|
||||
if($value === $this->attr('value')) {
|
||||
$this->submitValue = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
if(!count($this->dropdownItems)) return $this;
|
||||
|
||||
if(!$this->dropdownSubmit) {
|
||||
$name = $this->dropdownInputName;
|
||||
$value = $input->$name;
|
||||
}
|
||||
|
||||
if($value === null) return $this;
|
||||
|
||||
foreach($this->dropdownItems as $item) {
|
||||
if($value !== $item['value']) continue;
|
||||
$this->submitValue = $item['value'];
|
||||
break;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user