rooofl Posted June 6, 2023 Share Posted June 6, 2023 I am trying to use $config->jsConfig(). A very basic module I crafted does that after a page is saved: $this->wire('config')->jsConfig('mySettings', [ 'foo' => 'bar', 'bar' => 123, ]); … and the same module has a JS file that tries to get those data back: (right now I am sticking to the doc’s exemple as you can see) var mySettings = ProcessWire.config.mySettings; console.log(mySettings.foo); console.log(mySettings.bar) But that last JS returns “mySettings is undefined”. That is where I need some help. More generally, Is this the best way to deal with php <—> JS data interchange, considering my goal is to fill a field with js generated content with a URL from an upload field as parameter: Upload field in page edit -> fileURL -> javascript doStuff(fileURL) -> fill a PW field with the result of javascript doStuff(fileURL) Link to comment Share on other sites More sharing options...
bernhard Posted June 6, 2023 Share Posted June 6, 2023 Isn't it just $this->wire->config->js('mySettings', ...) ? Link to comment Share on other sites More sharing options...
rooofl Posted June 6, 2023 Author Share Posted June 6, 2023 I think both works, and my issue is more about retrieving this value once the pages is saved and reloaded: $this->wire('log')->save('vtf_custom', $this->wire("config")->js('mySettings')['foo']); returns “bar” as expected, but there is still no trace of “mySettings” in the js object ProcessWire.config when I log it. Link to comment Share on other sites More sharing options...
bernhard Posted June 6, 2023 Share Posted June 6, 2023 One possible solution: $wire->addHookBefore("Inputfield(name=title)::render", function ($event) { $f = $event->object; $id = $this->wire->input->get('id', 'int'); $f->appendMarkup = "<script>alert('You are editing page #$id')</script>"; }); 1 Link to comment Share on other sites More sharing options...
rooofl Posted June 6, 2023 Author Share Posted June 6, 2023 That solution works! Thank you! 1 Link to comment Share on other sites More sharing options...
rooofl Posted June 10, 2023 Author Share Posted June 10, 2023 Let me ask another question: could it be possible to log in JavaScript, the path of a file that just has been Ajax uploaded without saving the page? I tried that with no result: let uploadField = document.querySelector('#Inputfield_webfont_archive') uploadField.addEventListener("AjaxUploadDone", (e) => console.log(e)); 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