mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-08 03:01:43 +09:00
Fix error message when leaving current file unchanged in extra vars
This commit is contained in:
parent
65d68eec6d
commit
453f83db7d
3 changed files with 25 additions and 11 deletions
|
|
@ -1229,7 +1229,7 @@ class DocumentController extends Document
|
||||||
// Check for required and strict values.
|
// Check for required and strict values.
|
||||||
if (!$manual_updated)
|
if (!$manual_updated)
|
||||||
{
|
{
|
||||||
$ev_output = $extra_item->validate($value);
|
$ev_output = $extra_item->validate($value, $old_extra_vars[$idx]->value ?? null);
|
||||||
if ($ev_output && !$ev_output->toBool())
|
if ($ev_output && !$ev_output->toBool())
|
||||||
{
|
{
|
||||||
$oDB->rollback();
|
$oDB->rollback();
|
||||||
|
|
@ -1240,9 +1240,10 @@ class DocumentController extends Document
|
||||||
// Handle extra vars that support file upload.
|
// Handle extra vars that support file upload.
|
||||||
if ($extra_item->type === 'file')
|
if ($extra_item->type === 'file')
|
||||||
{
|
{
|
||||||
// New upload (replace old file)
|
// New upload
|
||||||
if (is_array($value) && isset($value['name']))
|
if (is_array($value) && isset($value['name']))
|
||||||
{
|
{
|
||||||
|
// Delete old file
|
||||||
if (isset($old_extra_vars[$idx]->value))
|
if (isset($old_extra_vars[$idx]->value))
|
||||||
{
|
{
|
||||||
$fc_output = FileController::getInstance()->deleteFile($old_extra_vars[$idx]->value);
|
$fc_output = FileController::getInstance()->deleteFile($old_extra_vars[$idx]->value);
|
||||||
|
|
@ -1252,14 +1253,13 @@ class DocumentController extends Document
|
||||||
return $fc_output;
|
return $fc_output;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Insert new file
|
||||||
$ev_output = $extra_item->uploadFile($value, $obj->document_srl, 'doc');
|
$ev_output = $extra_item->uploadFile($value, $obj->document_srl, 'doc');
|
||||||
if (!$ev_output->toBool())
|
if (!$ev_output->toBool())
|
||||||
{
|
{
|
||||||
$oDB->rollback();
|
$oDB->rollback();
|
||||||
return $ev_output;
|
return $ev_output;
|
||||||
}
|
}
|
||||||
|
|
||||||
$value = $ev_output->get('file_srl');
|
$value = $ev_output->get('file_srl');
|
||||||
}
|
}
|
||||||
// Delete current file
|
// Delete current file
|
||||||
|
|
@ -1267,6 +1267,14 @@ class DocumentController extends Document
|
||||||
{
|
{
|
||||||
if (isset($old_extra_vars[$idx]->value))
|
if (isset($old_extra_vars[$idx]->value))
|
||||||
{
|
{
|
||||||
|
// Check if deletion is allowed
|
||||||
|
$ev_output = $extra_item->validate(null);
|
||||||
|
if (!$ev_output->toBool())
|
||||||
|
{
|
||||||
|
$oDB->rollback();
|
||||||
|
return $ev_output;
|
||||||
|
}
|
||||||
|
// Delete old file
|
||||||
$fc_output = FileController::getInstance()->deleteFile($old_extra_vars[$idx]->value);
|
$fc_output = FileController::getInstance()->deleteFile($old_extra_vars[$idx]->value);
|
||||||
if (!$fc_output->toBool())
|
if (!$fc_output->toBool())
|
||||||
{
|
{
|
||||||
|
|
@ -2674,8 +2682,6 @@ class DocumentController extends Document
|
||||||
$js_code[] = 'var validator = xe.getApp("validator")[0];';
|
$js_code[] = 'var validator = xe.getApp("validator")[0];';
|
||||||
$js_code[] = 'if(!validator) return false;';
|
$js_code[] = 'if(!validator) return false;';
|
||||||
|
|
||||||
$logged_info = Context::get('logged_info');
|
|
||||||
|
|
||||||
foreach($extra_keys as $idx => $val)
|
foreach($extra_keys as $idx => $val)
|
||||||
{
|
{
|
||||||
$idx = $val->idx;
|
$idx = $val->idx;
|
||||||
|
|
@ -2683,9 +2689,11 @@ class DocumentController extends Document
|
||||||
{
|
{
|
||||||
$idx .= '[]';
|
$idx .= '[]';
|
||||||
}
|
}
|
||||||
$name = str_ireplace(array('<script', '</script'), array('<scr" + "ipt', '</scr" + "ipt'), $val->name);
|
$js_code[] = sprintf('validator.cast("ADD_MESSAGE", ["extra_vars%s", %s]);', $idx, var_export($val->name, true));
|
||||||
$js_code[] = sprintf('validator.cast("ADD_MESSAGE", ["extra_vars%s","%s"]);', $idx, $name);
|
if($val->is_required == 'Y' && $val->type !== 'file')
|
||||||
if($val->is_required == 'Y') $js_code[] = sprintf('validator.cast("ADD_EXTRA_FIELD", ["extra_vars%s", { required:true }]);', $idx);
|
{
|
||||||
|
$js_code[] = sprintf('validator.cast("ADD_EXTRA_FIELD", ["extra_vars%s", { required:true }]);', $idx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$js_code[] = '})(jQuery);';
|
$js_code[] = '})(jQuery);';
|
||||||
|
|
|
||||||
|
|
@ -232,9 +232,10 @@ class Value
|
||||||
* Validate a value.
|
* Validate a value.
|
||||||
*
|
*
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
|
* @param mixed $old_value
|
||||||
* @return ?BaseObject
|
* @return ?BaseObject
|
||||||
*/
|
*/
|
||||||
public function validate($value): ?BaseObject
|
public function validate($value, $old_value = null): ?BaseObject
|
||||||
{
|
{
|
||||||
// Take legacy encoding into consideration.
|
// Take legacy encoding into consideration.
|
||||||
if (is_array($value))
|
if (is_array($value))
|
||||||
|
|
@ -256,6 +257,11 @@ class Value
|
||||||
// Check if a required value is empty.
|
// Check if a required value is empty.
|
||||||
if ($this->is_required === 'Y')
|
if ($this->is_required === 'Y')
|
||||||
{
|
{
|
||||||
|
if ($this->type === 'file' && !$value && $old_value)
|
||||||
|
{
|
||||||
|
$value = $old_value;
|
||||||
|
$values = (array)$old_value;
|
||||||
|
}
|
||||||
if ($is_array && trim(implode('', $values)) === '')
|
if ($is_array && trim(implode('', $values)) === '')
|
||||||
{
|
{
|
||||||
return new BaseObject(-1, sprintf(lang('common.filter.isnull'), Context::replaceUserLang($this->name)));
|
return new BaseObject(-1, sprintf(lang('common.filter.isnull'), Context::replaceUserLang($this->name)));
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
<input type="file" name="{{ $input_name }}"
|
<input type="file" name="{{ $input_name }}"
|
||||||
id="{{ $input_id }}"|if="$input_id" class="file rx_ev_file"
|
id="{{ $input_id }}"|if="$input_id" class="file rx_ev_file"
|
||||||
style="{{ $definition->style }}"|if="$definition->style"
|
style="{{ $definition->style }}"|if="$definition->style"
|
||||||
@required(toBool($definition->is_required))
|
@required(toBool($definition->is_required) && !$value)
|
||||||
@disabled(toBool($definition->is_disabled))
|
@disabled(toBool($definition->is_disabled))
|
||||||
@readonly(toBool($definition->is_readonly))
|
@readonly(toBool($definition->is_readonly))
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue