codefog / contao-haste

Haste is a collection of tools and classes to ease working with Contao
http://codefog.pl/extension/haste.html
MIT License
43 stars 24 forks source link

Default value after Ajax reload #113

Closed a-kehr closed 6 years ago

a-kehr commented 6 years ago

Nach einem ajax-reload vom Formular werden die default-Werte leider nicht mehr gesetzt.

$objForm->addFormField(
            'lang',
            [
                'label'     => 'Label',
                'default'   => 3,
                'inputType' => 'select',
                'options'   => [1 => 'Sprache 1', 2 => 'Sprache 2', 3 => 'Sprache 3'],
            ]
        );

für ajax-reload wird folgende Erweiterung verwendet. richardhj/contao-ajax_reload_element

qzminski commented 6 years ago

I don't think this a Haste related issue. The form sets the value based on the $_POST data and if no data is given, then the default value is used. So logically thinking there already must be some data sent for that field in the AJAX request. Check the headers that are sent with the XHR and you will know what's the problem.

a-kehr commented 6 years ago

Hier ist die Feld definition

$objForm->addFormField(
            'spl_lang',
            [
                'label'     => 'Label',
                'default'   => \Contao\Input::post('spl_lang'),
                'inputType' => 'select',
                'options'   => [1 => 'Sprache 1', 2 => 'Sprache 2', 3 => 'Sprache 3'],
            ]
        );

Der Header sieht folgendermaßen aus haste-ajax

wenn ich mir die \Contao\Input::post('spl_lang') ausgebe, erhalte ich auch den gewählten Wert von 3