0

I trying to create a custom property editor for Umbraco 7 that talks to an external web service, retrieves some data then populates a number fields in the form with the data it's retrieved. I've tried doing this with the following simple code:

$("#textbox_id").val("new value");

This does indeed populate the correct field with the correct data. However if I save and reload the form the data has not been updated and value returns to it's original value.

Any suggestions?

8
  • does your external web service sends data properly after the form reload? Commented Jan 10, 2017 at 15:52
  • It shouldn't need to call the web service when the form reloads. The idea of it is that the data is then saved in Umbraco as regular content. Commented Jan 10, 2017 at 15:54
  • then it seems like the form data is not saved Commented Jan 10, 2017 at 15:56
  • That was the subject of my original question. I'm trying to work out why it's not being saved and how to make it save correctly. Commented Jan 10, 2017 at 15:58
  • 1
    I don't know your exact situation, but I guess you'll want to use angularjs to do the populating. This article helped me a lot: our.umbraco.org/documentation/tutorials/… Commented Jan 11, 2017 at 11:50

1 Answer 1

3

The problem is that you are using jQuery to update the input field directly in the DOM. The backoffice of Umbraco is completely wired up with an angular model and this model is not notified of the change in this input field when you are not actually typing in the field.

You can however trigger the input even on the form fields after updating the value of the field, which will ensure that angular gets notified of the change and it will update its model.

Something like this should get the job done and the change should now be included when you hit the save button:

$("#textbox_id").val("new value").trigger("input");
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, was using jQuery as am less familiar with angular. Must really brush up on angular when I get the chance.
Well there's really no problem in what you're doing. You just need to notify angular of the change to have the model updated, since it has no way of knowing that otherwise.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.