statamic / v2-hub

Statamic 2 - Feature Requests and Bug Reports
https://statamic.com
95 stars 5 forks source link

Provide a way to access fields in the CP #2502

Open dannyuk1982 opened 4 years ago

dannyuk1982 commented 4 years ago

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?