Как обновить значения Textarea в компоненте Filament с помощью JavaScript?Php

Кемеровские программисты php общаются здесь
Anonymous
Как обновить значения Textarea в компоненте Filament с помощью JavaScript?

Сообщение Anonymous »

Я хочу обновить значение textarea с помощью java-скрипта, но когда я отправляю слова, я могу получить только те данные, которые пользователи ввели непосредственно внутри textarea, а не изменения с помощью javascript
что мне делать?
здесь это мой код:
Translate::make()
->locales(['fa', 'en'])
->columnSpanFull()
->columns(2)
->schema(fn (string $locale) => [
Forms\Components\Select::make('variables')
->extraAttributes([
'onchange' => 'insertToTextarea("'.$locale.'")'
])
->options(NotificationTemplateVariableEnums::class),
Forms\Components\Textarea::make('template')
->required()
->columnSpanFull()
->reactive(),
])

// javascript
function insertToTextarea(locale) {
const textarea = document.getElementById('data.template.'+locale+'');
const variable = document.getElementById('data.variables.'+locale+'').value;
if (!textarea) return;

const start = textarea.selectionStart;
const end = textarea.selectionEnd;

const value = textarea.value;
textarea.value = value.slice(0, start) + variable + value.slice(end);

textarea.selectionStart = textarea.selectionEnd = start + variable.length;

textarea.focus();


protected function mutateFormDataBeforeSave(array $data): array
{dd($data);
}


Подробнее здесь: https://stackoverflow.com/questions/790 ... javascript

Вернуться в «Php»