간단한 버튼 $builder->add('language_switcher', ButtonType::class);
이있는 양식이 있는데,이를 누르면 다른 필드가 추가됩니다. 지금은 Buttons do not support event listeners.
그래서 내가 숨겨진 필드와 함께 밖으로 시도 오류를 받고 있어요 AJAX버튼을 누른 후 동적 양식 필드 추가하기
<script>
var $button = $('#xyz');
$button.click(function() {
var $form = $(this).closest('form');
$.ajax({
url: $form.attr('action'),
type: $form.attr('method'),
success: function(html) {
console.log(html);
$('#xyz').replaceWith($(html).find('#lang_switcher'));
}
});
});
</script>
그것을 제출할 때이를 위해, 나는 심포니의 요리 책 http://symfony.com/doc/current/form/dynamic_form_modification.html
$builder
->get('language_switcher')
->addEventListener(
FormEvents::POST_SUBMIT,
function() use ($builder, $options) {
$preparedOptions = $this->prepareOptions($options['data']['productCustomizations']);
$builder->add('lang_switcher'), ChoiceType::class, $preparedOptions);
}
);
을 사용했다. 나는 그러나이 아무것도하지 않았다, 양식에 숨겨진 필드를 추가 그것에 EventListener
를 설정하고 내 AJAX
요청
data[$('#id_of_hidden_field').attr('name')] = 1;
이 data
을 추가했습니다. 코믹 북의 예는 선택 필드를 제출 한 후이므로 내 필요에 맞게 조정하는 방법을 모르겠습니다. 나는 SubmitType
을 사용할 수 없었습니다. 양식을 제출했기 때문입니다. 맞습니까? 난 그냥 간단한 단추 만 갖고 싶어.
문제는, 내가 할 때 console.log(html)
새 html 요소가 보이지 않는다는 것입니다. 따라서 수신기에 내용을 덤프하면 EventListener
이 이상하게 들릴 것 같습니다. 약간의 데이터를 얻는 중입니다. 내가 응답 안에 들어 가지 못하는 것처럼 보입니다.
처럼 내장되어 있습니다 대신 학부모 (부모) 양식? 실제로 이벤트가 트리거됩니다. – Rvanlaak