WIP - create validation method for common object
This commit is contained in:
parent
be367c589f
commit
4d043b713c
@ -6380,10 +6380,9 @@ abstract class CommonObject
|
||||
* @param string $keyprefix Suffix string to add into name and id of field (can be used to avoid duplicate names)
|
||||
* @param string|int $morecss Value for css to define style/length of field. May also be a numeric.
|
||||
* @param int $nonewbutton Force to not show the new button on field that are links to object
|
||||
* @param int $mode 1=Used for search filters
|
||||
* @return string
|
||||
*/
|
||||
public function showInputField($val, $key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = 0, $nonewbutton = 0, $mode = 0)
|
||||
public function showInputField($val, $key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = 0, $nonewbutton = 0)
|
||||
{
|
||||
global $conf, $langs, $form;
|
||||
|
||||
@ -6399,16 +6398,13 @@ abstract class CommonObject
|
||||
// Validation tests and output
|
||||
$fieldValidationErrorMsg = '';
|
||||
$validationClass = '';
|
||||
if ($mode == 0) {
|
||||
$fieldValidationErrorMsg = $this->getFieldError($key);
|
||||
if (!empty($fieldValidationErrorMsg)) {
|
||||
$validationClass = ' --error'; // the -- is use as class state in css : .--error can't be be defined alone it must be define with another class like .my-class.--error or input.--error
|
||||
} else {
|
||||
$validationClass = ' --success'; // the -- is use as class state in css : .--success can't be be defined alone it must be define with another class like .my-class.--success or input.--success
|
||||
}
|
||||
$fieldValidationErrorMsg = $this->getFieldError($key);
|
||||
if (!empty($fieldValidationErrorMsg)) {
|
||||
$validationClass = ' --error'; // the -- is use as class state in css : .--error can't be be defined alone it must be define with another class like .my-class.--error or input.--error
|
||||
} else {
|
||||
$validationClass = ' --success'; // the -- is use as class state in css : .--success can't be be defined alone it must be define with another class like .my-class.--success or input.--success
|
||||
}
|
||||
|
||||
|
||||
$out = '';
|
||||
$type = '';
|
||||
$isDependList=0;
|
||||
@ -6972,7 +6968,7 @@ abstract class CommonObject
|
||||
*/
|
||||
|
||||
// Display error message for field
|
||||
if ($mode == 0 && !empty($fieldValidationErrorMsg) && function_exists('getFieldErrorIcon')) {
|
||||
if (!empty($fieldValidationErrorMsg) && function_exists('getFieldErrorIcon')) {
|
||||
$out .= ' '.getFieldErrorIcon($fieldValidationErrorMsg);
|
||||
}
|
||||
|
||||
@ -7335,6 +7331,9 @@ abstract class CommonObject
|
||||
*/
|
||||
public function setFieldError($fieldKey, $msg = '')
|
||||
{
|
||||
global $langs;
|
||||
if (empty($msg)) { $msg = $langs->trans("UnknowError"); }
|
||||
|
||||
$this->error = $this->validateFieldsErrors[$fieldKey] = $msg;
|
||||
}
|
||||
|
||||
@ -7369,6 +7368,7 @@ abstract class CommonObject
|
||||
$this->clearFieldError($fieldKey);
|
||||
|
||||
if (!isset($val[$fieldKey])) {
|
||||
$this->setFieldError($fieldKey, $langs->trans('FieldNotFoundInObject'));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -9756,13 +9756,14 @@ function dolGetButtonTitleSeparator($moreClass = "")
|
||||
/**
|
||||
* get field error icon
|
||||
*
|
||||
* @param string $fieldValidationErrorMsg
|
||||
* @param string $fieldValidationErrorMsg message to add in tooltip
|
||||
* @return string html output
|
||||
*/
|
||||
function getFieldErrorIcon($fieldValidationErrorMsg)
|
||||
{
|
||||
$out = '';
|
||||
if (!empty($fieldValidationErrorMesg)) {
|
||||
$out.= '<span class="field-error-icon fa fa-exclamation-circle classfortooltip" title="'.dol_escape_htmltag($fieldValidationErrorMsg, 1).'" role="alert" >'; // role alert is used for accessibility
|
||||
if (!empty($fieldValidationErrorMsg)) {
|
||||
$out.= '<span class="field-error-icon classfortooltip" title="'.dol_escape_htmltag($fieldValidationErrorMsg, 1).'" role="alert" >'; // role alert is used for accessibility
|
||||
$out.= '<span class="fa fa-exclamation-circle" aria-hidden="true" ></span>'; // For accessibility icon is separated and aria-hidden
|
||||
$out.= '</span>';
|
||||
}
|
||||
|
||||
@ -101,16 +101,16 @@ class MyObject extends CommonObject
|
||||
*/
|
||||
public $fields = array(
|
||||
'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'noteditable'=>1, 'notnull'=> 1, 'index'=>1, 'position'=>1, 'comment'=>'Id', 'css'=>'left'),
|
||||
'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>1, 'noteditable'=>0, 'default'=>'', 'notnull'=> 1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'),
|
||||
'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>1, 'noteditable'=>0, 'default'=>'', 'notnull'=> 1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object', 'validate'=>1),
|
||||
'entity' => array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'notnull'=> 1, 'default'=>1, 'index'=>1, 'position'=>20),
|
||||
'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'searchall'=>1, 'css'=>'minwidth300', 'cssview'=>'wordbreak', 'help'=>'Help text', 'showoncombobox'=>1),
|
||||
'amount' => array('type'=>'price', 'label'=>'Amount', 'enabled'=>1, 'visible'=>1, 'default'=>'null', 'position'=>40, 'searchall'=>0, 'isameasure'=>1, 'help'=>'Help text for amount'),
|
||||
'qty' => array('type'=>'real', 'label'=>'Qty', 'enabled'=>1, 'visible'=>1, 'default'=>'0', 'position'=>45, 'searchall'=>0, 'isameasure'=>1, 'help'=>'Help text for quantity', 'css'=>'maxwidth75imp'),
|
||||
'fk_soc' => array('type'=>'integer:Societe:societe/class/societe.class.php:1:status=1 AND entity IN (__SHARED_ENTITIES__)', 'picto'=>'company', 'label'=>'ThirdParty', 'visible'=> 1, 'enabled'=>1, 'position'=>50, 'notnull'=>-1, 'index'=>1, 'help'=>'LinkToThirparty'),
|
||||
'fk_project' => array('type'=>'integer:Project:projet/class/project.class.php:1', 'label'=>'Project', 'picto'=>'project', 'enabled'=>1, 'visible'=>-1, 'position'=>52, 'notnull'=>-1, 'index'=>1),
|
||||
'description' => array('type'=>'text', 'label'=>'Description', 'enabled'=>1, 'visible'=>3, 'position'=>60),
|
||||
'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>61),
|
||||
'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>62),
|
||||
'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'searchall'=>1, 'css'=>'minwidth300', 'cssview'=>'wordbreak', 'help'=>'Help text', 'showoncombobox'=>1, 'validate'=>1),
|
||||
'amount' => array('type'=>'price', 'label'=>'Amount', 'enabled'=>1, 'visible'=>1, 'default'=>'null', 'position'=>40, 'searchall'=>0, 'isameasure'=>1, 'help'=>'Help text for amount', 'validate'=>1),
|
||||
'qty' => array('type'=>'real', 'label'=>'Qty', 'enabled'=>1, 'visible'=>1, 'default'=>'0', 'position'=>45, 'searchall'=>0, 'isameasure'=>1, 'help'=>'Help text for quantity', 'css'=>'maxwidth75imp', 'validate'=>1),
|
||||
'fk_soc' => array('type'=>'integer:Societe:societe/class/societe.class.php:1:status=1 AND entity IN (__SHARED_ENTITIES__)', 'picto'=>'company', 'label'=>'ThirdParty', 'visible'=> 1, 'enabled'=>1, 'position'=>50, 'notnull'=>-1, 'index'=>1, 'help'=>'LinkToThirparty', 'validate'=>1),
|
||||
'fk_project' => array('type'=>'integer:Project:projet/class/project.class.php:1', 'label'=>'Project', 'picto'=>'project', 'enabled'=>1, 'visible'=>-1, 'position'=>52, 'notnull'=>-1, 'index'=>1, 'validate'=>1),
|
||||
'description' => array('type'=>'text', 'label'=>'Description', 'enabled'=>1, 'visible'=>3, 'position'=>60, 'validate'=>1),
|
||||
'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>61, 'validate'=>1),
|
||||
'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>62, 'validate'=>1),
|
||||
'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'notnull'=> 1, 'position'=>500),
|
||||
'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'notnull'=> 0, 'position'=>501),
|
||||
//'date_validation ' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>502),
|
||||
@ -120,7 +120,7 @@ class MyObject extends CommonObject
|
||||
'last_main_doc' => array('type'=>'varchar(255)', 'label'=>'LastMainDoc', 'enabled'=>1, 'visible'=>0, 'notnull'=>0, 'position'=>600),
|
||||
'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'index'=>0, 'position'=>1000),
|
||||
'model_pdf' => array('type'=>'varchar(255)', 'label'=>'Model pdf', 'enabled'=>1, 'visible'=>0, 'notnull'=>-1, 'position'=>1010),
|
||||
'status' => array('type'=>'smallint', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'notnull'=> 1, 'default'=>0, 'index'=>1, 'position'=>1000, 'arrayofkeyval'=>array(0=>'Draft', 1=>'Validated', 9=>'Canceled')),
|
||||
'status' => array('type'=>'smallint', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'notnull'=> 1, 'default'=>0, 'index'=>1, 'position'=>1000, 'arrayofkeyval'=>array(0=>'Draft', 1=>'Validated', 9=>'Canceled'), 'validate'=>1),
|
||||
);
|
||||
|
||||
/**
|
||||
|
||||
@ -234,10 +234,12 @@ input.button.massactionconfirmed {
|
||||
margin: 4px;
|
||||
}
|
||||
|
||||
input:invalid, select:invalid {
|
||||
input:invalid, select:invalid, input.--error , select.--error {
|
||||
border-color: #ea1212;
|
||||
}
|
||||
|
||||
.field-error-icon { color: #ea1212; !important; }
|
||||
|
||||
/* Focus definitions must be after standard definition */
|
||||
textarea:focus {
|
||||
border: 1px solid #aaa !important;
|
||||
@ -433,7 +435,7 @@ input.pageplusone {
|
||||
transform: scale(-1, 1);
|
||||
}
|
||||
|
||||
select:invalid {
|
||||
select:invalid, select.--error {
|
||||
color: gray;
|
||||
}
|
||||
input:disabled, textarea:disabled, select[disabled='disabled']
|
||||
@ -2076,7 +2078,7 @@ span.widthpictotitle.pictotitle {
|
||||
vertical-align: middle;
|
||||
margin-top: -3px
|
||||
}
|
||||
.pictowarning, .pictoerror, .pictopreview {
|
||||
.pictowarning, .picto.error, .pictopreview {
|
||||
padding-<?php echo $left; ?>: 3px;
|
||||
}
|
||||
.pictowarning {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user