netcarver Posted July 18, 2018 Share Posted July 18, 2018 Hello all, Can anyone point me in the right direction here. When editing the pages of a certain template, I have a tab (Fieldset Tab Open) into which I've added a runtime markup field which does state verification and, if all's good, adds an email send button to the page. I have a pages::saved() hook that takes care of the actual send should the button be clicked. This works fine, and is out on a production server, but it has a drawback; it requires the user to save the page before the information used to generate the send button is in sync with any changes the user has made. Even if I make the tab ajax load, this only works for the first set of changes the user makes, ie, when they switch to the tab for the first time. If they go back to one of the regular content tabs and make an additional change, the content of the send tab is now potentially stale and requires a re-save to freshen it. To help with this workflow, I'd like to make it so that the very act of clicking on the send tab activates a page save, if needed, ensuring the content of the send tab is always in sync with the stored data. State of page changes is tracked by JS already - so this must be possible. Whilst I'm sure I can patch my way to a solution, any help short-cutting that route would be appreciated. Many thanks in advance, Steve 1 Link to comment Share on other sites More sharing options...
Zeka Posted July 18, 2018 Share Posted July 18, 2018 There is 'wiretabclick' event in JqueryWireTabs that you can use to trigger page save. https://github.com/processwire/processwire/blob/50f2834a0ae2a9f9f2ac53439184ebdc04db2f54/wire/modules/Jquery/JqueryWireTabs/README.txt#L31 Also, it worth to look at @tprs realization of hotkey save in the AdminOnSteroid module. 1 Link to comment Share on other sites More sharing options...
netcarver Posted July 18, 2018 Author Share Posted July 18, 2018 @Zeka Thanks for the pointers. I'll take a look. I can trigger the save with some injected JS - it's just figuring out how to make it conditional that I'm hung up on at the moment. Will do some grepping and see what that turns up, too. Link to comment Share on other sites More sharing options...
netcarver Posted July 18, 2018 Author Share Posted July 18, 2018 Well, I found Soma's old FormSaveReminder module - which I can dissect, but I've not found the code PW currently uses, despite grepping for the message you get when you move away from a page with unsaved edits. Perhaps my grep skills are rusty. Update: Ok, thanks to this old blog post, I'm pretty sure I've found what I need. Will post solution once it's come together. Link to comment Share on other sites More sharing options...
netcarver Posted July 18, 2018 Author Share Posted July 18, 2018 All done. Simpler than I thought it would be in the end... $(document).on('wiretabclick', function(event, newTab, oldTab) { old_id = oldTab.attr('id'); new_id = newTab.attr('id'); if ((old_id !== new_id) && (new_id === 'Inputfield_mailing_actions')) { var changes = $(".InputfieldFormConfirm:not(.InputfieldFormSubmitted) .InputfieldStateChanged"); if(changes.length !== 0) { $('#Inputfield_save_btn').click(); } } }); The missing code was in the templates-admin/scripts/inputfields.js file at line 901. 3 Link to comment Share on other sites More sharing options...
Zeka Posted July 18, 2018 Share Posted July 18, 2018 @netcarver Great that you solve the issue, but as the further enhancement it would be nice to save field via ajax. I have found this module that intended to do it https://github.com/Klenkes/AjaxSave. So, maybe you can adapt it to your project needs. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now