This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

chris10207
chris10207

Does anyone manage to understand and use for form_ajax tag with component ?

my objective is as follow: i have a list of data, lets say people, displayed on a page. i have a 'New' button and an 'edit' button atached to each people. the New button should update a div with a partial loaded via ajaxRequest. this is done with :

a href="nojavascript...;"  data-request="onNewPeople" data-request-success="$.sbaForm.toggleEditMode('#partialPeopleForm')" data-request-update="'@form/people-form': '#partialForm">

the handler onNew in the compoennt does not perform anything, it is here just to allow the update of the partial loaded trough ajax.

now in this partial, there is a form like this :

 {{ form_ajax( 'onSavePeople', { model: people} ) }}

This is where things get a confused, from here i would need to perform :

  • onSave method in the component will handle the form validation
  • if any validation error, then send a flash error message to the current form so that the user can fix the issues and submit again.
  • if no error, then i need to perform 2 actions : hide the people form (trough javascript) and show and refresh the people partial list ( trough a render of partials)

how can we do that ?

i tried to play with the error and success and update properties of the form_ajax, but it does not work as expected. for instance, the success handler is always triggered even if i throw an exception from the onSavePeople method

1-1 of 1

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.