Is it ok to redirect response to edit modal on insert?

Is it good practice to do this?

	$crud->callbackAfterInsert(function ($stateParameters) {

		$redirectResponse = new \GroceryCrud\Core\Redirect\RedirectResponse();
		return $redirectResponse->setUrl(base_url().'/SanController/san_records#/edit/' . $stateParameters->insertId);

	});

I think the only thing I note that it does not refresh the datagrid in the background when you do this.

So question is, it there a way to force a refresh of the datagrid in the backgound behind the modal?

Hello @markab ,

I guess you are looking for the JavaScript trigger?

document.querySelector(".gc-container .fa-refresh").click();

Regards
Johnny

1 Like

So in my view i added…

	<script>
			
			function refreshDoc() {
			
				document.querySelector(".gc-container .fa-refresh").click();
			}
			
				
	</script>

If I call it from <button onclick="refreshDoc()">Try it</button>

It works fine.

However if I add an event…

window.addEventListener("load", function(){refreshDoc()});

I get the following console error…

san_records:30 Uncaught TypeError: Cannot read properties of null (reading ‘click’)

moved the script element and now no error but when the page redirect runs it still does not refresh the data grid behind.

Still not been able to implement this.

What I essentially want to do is change the close modal on save behaviour.

In the Add form when close modal on save is checked then the modal closes.

In the Add form when close modal on save is not checked then the modal stays open and after save of the insert form then renders the modal as the edit form, so you can make an insert and incremental edits without closing.

In the Edit form when close modal on save is checked then the modal closes.

In the Edit form when close modal on save is not checked then the modal stays open and refreshes the edit form. Now I think this is what it is supposed to do but it only refreshes the datagrid in the background. If you had a callbackBeforeUpdate which modifies a field before update and the modal is set to stay open it does not refresh the edit form with that change.