From 0f4977727a05bf3e2993051ff97b62ac08a91967 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Fri, 23 Dec 2022 22:10:14 +0800 Subject: [PATCH] feat(web): UOJForm::addInput() --- web/app/models/UOJForm.php | 49 +++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/web/app/models/UOJForm.php b/web/app/models/UOJForm.php index 349e6d3..b022fef 100644 --- a/web/app/models/UOJForm.php +++ b/web/app/models/UOJForm.php @@ -120,6 +120,53 @@ class UOJForm { $this->add($name, $html, $validator_php, $validator_js); } + public function addInput($name, $config) { + $config += [ + 'type' => 'text', + 'div_class' => '', + 'input_class' => 'form-control', + 'default_value' => '', + 'label' => '', + 'label_class' => 'form-label', + 'placeholder' => '', + 'help' => '', + 'help_class' => '', + 'validator_php' => function ($x) { + return ''; + }, + 'validator_js' => null, + ]; + + $html = ''; + $html .= HTML::tag_begin('div', ['class' => $config['div_class'], 'id' => "div-$name"]); + + if ($config['label']) { + $html .= HTML::tag('label', [ + 'class' => $config['label_class'], + 'for' => "input-$name", + 'id' => "label-$name" + ], $config['label']); + } + + $html .= HTML::empty_tag('input', [ + 'class' => $config['input_class'], + 'type' => $config['type'], + 'name' => $name, + 'id' => "input-$name", + 'value' => $config['default_value'], + 'placeholder' => $config['placeholder'], + ]); + $html .= HTML::tag('div', ['class' => 'invalid-feedback', 'id' => "help-$name"], ''); + + if ($config['help']) { + $html .= HTML::tag('div', ['class' => $config['help_class']], $config['help']); + } + + $html .= HTML::tag_end('div'); + + $this->add($name, $html, $config['validator_php'], $config['validator_js']); + } + public function addCheckbox($name, $config) { $config += [ 'checked' => false, @@ -346,7 +393,7 @@ class UOJForm { } if ($this->config['confirm']['smart']) { - $this->config['confirm']['text'] = '你真的要' . $this->config['submit']['text'] . '吗?'; + $this->config['confirm']['text'] = '你真的要' . $this->config['submit_button']['text'] . '吗?'; } if ($this->config['confirm']['text']) { echo <<