I've recently needed to access the fields in a CP publish form via JS for a couple of addons, there seems to be no way to do this. I've found:
1) Horrible hacky way with jQuery/document.QuerySelector to grab the inputs in .publish-fields, this then breaks if you change the order of fields
2) Hack statamic/resources/dist/app.js so the new Vue({el:"#statamic"... is given a reference, i.e. window.vue = new Vue({el:"#statamic"..., this means you can then do something like
var fields = vue.$children[2].formData.fields;
alert(fields.my_other_field);
fields.my_field = "my new value";
etc. Obviously any updates to core that change app.js will break this.
Can an official way be implemented for this, even if you just add a reference to the main vue model as per solution 2?
I've recently needed to access the fields in a CP publish form via JS for a couple of addons, there seems to be no way to do this. I've found:
1) Horrible hacky way with jQuery/document.QuerySelector to grab the inputs in
.publish-fields
, this then breaks if you change the order of fields2) Hack
statamic/resources/dist/app.js
so thenew Vue({el:"#statamic"...
is given a reference, i.e.window.vue = new Vue({el:"#statamic"...
, this means you can then do something likeetc. Obviously any updates to core that change app.js will break this.
Can an official way be implemented for this, even if you just add a reference to the main vue model as per solution 2?