MDL-65069 core_form: Expose the form's submit's class attribute

Exposed the submit button's class attribute so it can be overriden by
custom classes provided by the programmer.
This commit is contained in:
Peter 2019-03-27 15:21:24 +08:00
parent 97babbf7d7
commit e455d6f483
3 changed files with 30 additions and 6 deletions

View File

@ -48,6 +48,13 @@ class MoodleQuickForm_submit extends HTML_QuickForm_submit implements templatabl
*/
protected $primary;
/**
* Any class apart from 'btn' would be override with this content
*
* @var string $customclassoverride Custom class override for the input element
*/
protected $customclassoverride;
/**
* constructor
*
@ -65,6 +72,12 @@ class MoodleQuickForm_submit extends HTML_QuickForm_submit implements templatabl
} else {
$this->primary = $primary;
}
$class = $this->getAttribute('customclassoverride');
if ($class) {
$this->removeAttribute('customclassoverride');
$this->customclassoverride = $class;
}
}
/**
@ -131,6 +144,10 @@ class MoodleQuickForm_submit extends HTML_QuickForm_submit implements templatabl
if (!$this->primary) {
$context['secondary'] = true;
}
if ($this->customclassoverride) {
$context['customclass'] = $this->customclassoverride;
}
return $context;
}
}

View File

@ -3,9 +3,12 @@
{{^element.frozen}}
<input type="submit"
class="btn
{{^element.secondary}}btn-primary{{/element.secondary}}
{{#element.secondary}}btn-secondary{{/element.secondary}}
{{#error}} btn-danger {{/error}}"
{{^element.customclass}}
{{^element.secondary}}btn-primary{{/element.secondary}}
{{#element.secondary}}btn-secondary{{/element.secondary}}
{{/element.customclass}}
{{#error}} btn-danger {{/error}}
{{#element.customclass}}{{element.customclass}}{{/element.customclass}}"
name="{{element.name}}"
id="{{element.id}}"
value="{{element.value}}"

View File

@ -3,9 +3,13 @@
{{^element.frozen}}
<input type="submit"
class="btn
{{^element.secondary}}btn-primary{{/element.secondary}}
{{#element.secondary}}btn-secondary{{/element.secondary}}
{{#error}} btn-danger {{/error}}"
{{^element.customclass}}
{{^element.secondary}}btn-primary{{/element.secondary}}
{{#element.secondary}}btn-secondary{{/element.secondary}}
{{/element.customclass}}
{{#error}} btn-danger {{/error}}
{{element.extraclasses}}
{{#element.customclass}}{{element.customclass}}{{/element.customclass}}"
name="{{element.name}}"
id="{{element.id}}"
{{#error}}