From d4ae271b102a01f21041f1068a6806f26efa3419 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come@opensides.be> Date: Tue, 16 Oct 2018 17:40:08 +0200 Subject: [PATCH] :sparkles: feat(attributes) Set HTML5 required attribute for required inputs issue #5910 --- .../attributes/class_FileAttribute.inc | 2 +- .../attributes/class_IntAttribute.inc | 3 +++ .../attributes/class_SetAttribute.inc | 8 ++++---- .../attributes/class_StringAttribute.inc | 7 ++++++- .../simpleplugin/class_dialogAttributes.inc | 20 +++++++++++++------ setup/setup_migrate_adminAccount.tpl | 2 +- setup/setup_migrate_baseOC.tpl | 2 +- 7 files changed, 30 insertions(+), 14 deletions(-) diff --git a/include/simpleplugin/attributes/class_FileAttribute.inc b/include/simpleplugin/attributes/class_FileAttribute.inc index 2ad49b65e..388112074 100644 --- a/include/simpleplugin/attributes/class_FileAttribute.inc +++ b/include/simpleplugin/attributes/class_FileAttribute.inc @@ -169,7 +169,7 @@ class FileDownloadAttribute extends FileAttribute $display = ''; if ($this->upload) { $display .= $this->renderInputField('file', $id); - $display .= $this->renderInputField('submit', 'upload'.$id, array('value' => _('Upload'))); + $display .= $this->renderInputField('submit', 'upload'.$id, array('value' => _('Upload'), 'formnovalidate' => 'formnovalidate')); } $display .= $this->renderInputField( 'image', 'download'.$id, diff --git a/include/simpleplugin/attributes/class_IntAttribute.inc b/include/simpleplugin/attributes/class_IntAttribute.inc index 476f16607..7ca5e4215 100644 --- a/include/simpleplugin/attributes/class_IntAttribute.inc +++ b/include/simpleplugin/attributes/class_IntAttribute.inc @@ -108,6 +108,9 @@ class IntAttribute extends Attribute $js = $this->managedAttributesJS(); $attributes['onChange'] = 'javascript:'.htmlentities($js, ENT_COMPAT, 'UTF-8'); } + if ($this->isRequired()) { + $attributes['required'] = 'required'; + } $display = $this->renderInputField('number', $id, $attributes); return $this->renderAcl($display); } diff --git a/include/simpleplugin/attributes/class_SetAttribute.inc b/include/simpleplugin/attributes/class_SetAttribute.inc index ddd05f6f8..90d16938d 100644 --- a/include/simpleplugin/attributes/class_SetAttribute.inc +++ b/include/simpleplugin/attributes/class_SetAttribute.inc @@ -43,7 +43,7 @@ class SetAttribute extends Attribute $values ); $this->attribute = $attribute; - $this->attribute->setRequired(TRUE); + $this->attribute->setRequired(FALSE); $this->valueUnicity = $valueUnicity; } @@ -278,8 +278,8 @@ class SetAttribute extends Attribute function renderButtons () { $id = $this->getHtmlId(); - $buttons = $this->renderInputField('submit', 'add'.$id, array('value' => '{msgPool type=addButton}')); - $buttons .= $this->renderInputField('submit', 'del'.$id, array('value' => '{msgPool type=delButton}')); + $buttons = $this->renderInputField('submit', 'add'.$id, array('value' => '{msgPool type=addButton}', 'formnovalidate' => 'formnovalidate')); + $buttons .= $this->renderInputField('submit', 'del'.$id, array('value' => '{msgPool type=delButton}', 'formnovalidate' => 'formnovalidate')); return $buttons; } @@ -656,7 +656,7 @@ class OrderedArrayAttribute extends SetAttribute function renderButtons () { $id = $this->getHtmlId(); - $buttons = $this->renderInputField('submit', 'add'.$id, array('value' => '{msgPool type=addButton}')); + $buttons = $this->renderInputField('submit', 'add'.$id, array('value' => '{msgPool type=addButton}', 'formnovalidate' => 'formnovalidate')); return $buttons; } } diff --git a/include/simpleplugin/attributes/class_StringAttribute.inc b/include/simpleplugin/attributes/class_StringAttribute.inc index 632ec4bea..f76587bae 100644 --- a/include/simpleplugin/attributes/class_StringAttribute.inc +++ b/include/simpleplugin/attributes/class_StringAttribute.inc @@ -80,6 +80,9 @@ class StringAttribute extends Attribute if ($this->html5pattern !== NULL) { $attributes['pattern'] = htmlentities($this->html5pattern, ENT_COMPAT, 'UTF-8'); } + if ($this->isRequired()) { + $attributes['required'] = 'required'; + } $display = $this->renderInputField($this->inputType, $id, $attributes); return $this->renderAcl($display); } @@ -153,7 +156,9 @@ class TextAreaAttribute extends StringAttribute { $id = $this->getHtmlId(); $display = '<textarea name="'.$id.'" id="'.$id.'"'. - ($this->disabled ? ' disabled="disabled"' : '').'>'. + ($this->disabled ? ' disabled="disabled"' : ''). + ($this->isRequired() ? ' required="required"' : ''). + '>'. '{literal}'.htmlentities($this->getValue(), ENT_COMPAT, 'UTF-8').'{/literal}</textarea>'; return $this->renderAcl($display); } diff --git a/include/simpleplugin/class_dialogAttributes.inc b/include/simpleplugin/class_dialogAttributes.inc index c0169875b..997f56026 100644 --- a/include/simpleplugin/class_dialogAttributes.inc +++ b/include/simpleplugin/class_dialogAttributes.inc @@ -249,20 +249,27 @@ class DialogAttribute extends SetAttribute ); $buttons .= $this->renderInputField( 'submit', 'add'.$id, - array('value' => '{msgPool type=addButton}') + array( + 'value' => '{msgPool type=addButton}', + 'formnovalidate' => 'formnovalidate' + ) ); $dialogButtonValue = _('Add (dialog)'); } $buttons .= $this->renderInputField( 'submit', 'add'.$id.'_dialog', array( - 'class' => 'dialog', - 'value' => $dialogButtonValue + 'class' => 'dialog', + 'value' => $dialogButtonValue, + 'formnovalidate' => 'formnovalidate' ) ); $buttons .= $this->renderInputField( 'submit', 'del'.$id, - array('value' => '{msgPool type=delButton}') + array( + 'value' => '{msgPool type=delButton}', + 'formnovalidate' => 'formnovalidate' + ) ); return $buttons; } @@ -337,8 +344,9 @@ class DialogOrderedArrayAttribute extends OrderedArrayAttribute return $this->renderInputField( 'submit', 'add'.$id.'_dialog', array( - 'class' => 'dialog', - 'value' => '{msgPool type=addButton}' + 'class' => 'dialog', + 'value' => '{msgPool type=addButton}', + 'formnovalidate' => 'formnovalidate' ) ); } diff --git a/setup/setup_migrate_adminAccount.tpl b/setup/setup_migrate_adminAccount.tpl index ae5ca8bbc..a7cd35fff 100644 --- a/setup/setup_migrate_adminAccount.tpl +++ b/setup/setup_migrate_adminAccount.tpl @@ -51,7 +51,7 @@ <hr/> <div style='width:99%; text-align:right; padding:5px;'> <input type='submit' name='dialog_confirm' value='{t}Apply{/t}'/> - <input type='submit' name='dialog_cancel' value='{t}Cancel{/t}'/> + <input type='submit' formnovalidate="formnovalidate" name='dialog_cancel' value='{t}Cancel{/t}'/> </div> </div> </div> diff --git a/setup/setup_migrate_baseOC.tpl b/setup/setup_migrate_baseOC.tpl index 4a85846df..bec45cc2f 100644 --- a/setup/setup_migrate_baseOC.tpl +++ b/setup/setup_migrate_baseOC.tpl @@ -22,7 +22,7 @@ <hr/> <div style='width:100%; text-align:right; padding:5px;'> - <input type='submit' name='dialog_cancel' value='{t}Close{/t}'> + <input type='submit' formnovalidate="formnovalidate" name='dialog_cancel' value='{t}Close{/t}'> </div> </div> </div> -- GitLab