Load value to editor form field using custom button, depedent other field value
Load value to editor form field using custom button, depedent other field value
I need help creating a button in the editor form that will load a default value into the Y field based on the X field.
I have a php script that will return the correct load.key.php value
formButtons: [
{
text: 'Load default key',
className: 'btn btn-primary btn-md',
action: function () {
$ .ajax ({
type: 'POST',
data: 'values% 5Bmeters.model% 5D = 32',
url: 'php / load-key.php',
});
},
},
Pressing the button starts the script, but I have a problem with loading the result into the field in the editor and loading the parameter into the php script, in this case "32"
I also do not know what should be returned json, currently it looks like this:
[{"meters.encryption_key": "00000000000000000000000000000000"}]
the field where I want to load the value is meters.encryption_key
the field from which I want to get the ID for the query is meters.model
Thanks in advance for your help, I just got started with javascript
This question has an accepted answers - jump to answer
Answers
It can be whatever you want - it is your Ajax call and you'll need to process it . I'd suggest probably just an object with the value you want to set. You'll need to add a
success
callback function that will take the value from the JSON and put it into the Editor form - probably usingfield().val()
.Allan
Thanks for quick reply!
already correctly loads the model into the query, but I'm having still trouble loading the value into the field
The answer in the browser looks ok
data.val
isn't correct for that JSON return. You have it in an array and the property iskey
, so use:Allan