Fix error message when leaving current file unchanged in extra vars

This commit is contained in:
Kijin Sung 2024-10-09 02:36:28 +09:00
parent 65d68eec6d
commit 453f83db7d
3 changed files with 25 additions and 11 deletions

View file

@ -232,9 +232,10 @@ class Value
* Validate a value.
*
* @param mixed $value
* @param mixed $old_value
* @return ?BaseObject
*/
public function validate($value): ?BaseObject
public function validate($value, $old_value = null): ?BaseObject
{
// Take legacy encoding into consideration.
if (is_array($value))
@ -256,6 +257,11 @@ class Value
// Check if a required value is empty.
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)) === '')
{
return new BaseObject(-1, sprintf(lang('common.filter.isnull'), Context::replaceUserLang($this->name)));

View file

@ -17,7 +17,7 @@
<input type="file" name="{{ $input_name }}"
id="{{ $input_id }}"|if="$input_id" class="file rx_ev_file"
style="{{ $definition->style }}"|if="$definition->style"
@required(toBool($definition->is_required))
@required(toBool($definition->is_required) && !$value)
@disabled(toBool($definition->is_disabled))
@readonly(toBool($definition->is_readonly))
/>