Anguilla - Updating field value from popup?

I have a modal popup that appears whenever the editor tries to save the component with some values ​​(a date field in the past in this case).

In this pop-up window, I will show the editor a few options (very similar to the Open Common Element dialog box by default) and the OK / Cancel button combination. In the "Cancel" field, I fire the "cancel" event, and the editor returns to the editing screen, everything is fine here. In "OK" I want to change the value of the field in accordance with the selected editor, and then save.

I tried using the FieldBuilder approach and the Boris sample mentioned in this other section , but I cannot get into the field from my pop-up dialog box.

Any suggestions on how I can go and change the xml of an element (maybe also a page) from a modal popup?

EDIT: Code Used in getControlForFieldName

function getControlForFieldName(name) { var fieldBuilder = $display.getView().properties.controls.fieldBuilder; var fieldsContainer = fieldBuilder.properties.input; var fieldsNode = fieldsContainer.getElement(); var fieldContainer = $dom.getFirstElementChild(fieldsNode); while (fieldContainer) { var labelNode = $dom.getFirstElementChild(fieldContainer); var fieldNode = $dom.getNextElementSibling(labelNode); var control = fieldNode.control; if (control.getFieldName() == name) { return control; } fieldContainer = $dom.getNextElementSibling(fieldContainer); } } 

CHANGE No. 2

After Frank advised, and some help from Jaime and Frank offline, I got him to work as follows:

  • The popup menu is called from the command line (Save and close in my case)
  • The command.js command indicates an event handler that is called on "submit" (OK was pressed)
 $evt.addEventHandler(p.dialogPopup, "submit", this.getDelegate(this._onPopupSubmit)); 

In my popup, I pass the selected item (this is the keyword identifier) ​​to the event handler:

 this.fireEvent("submit", { id: select.options[select.selectedIndex].value }); 

and now in the _onPopupSubmit(e) event handler I just read e.data.id, load this keyword, get properties like ID and Title, and update the item metadata using item.setMetadata ("new metadata with updated values") .

Plain:)

+6
source share
1 answer

Your code runs in a popup window, so any references you make to global variables will be taken from the popup window.

So, when you get fieldBuilder:

 var fieldBuilder = $display.getView().properties.controls.fieldBuilder; 

$ display - a reference to a global variable. Thus, it is actually looking for a FieldBuilder in a popup window (which doesn't have one).

To get the FieldBuilder window in the Component window, you can get it from the opener:

 var fieldBuilder = opener.$display.getView().properties.controls.fieldBuilder; 

Maybe you should consider passing the updated value either to the callback function, or using a (custom) event, as this makes your popup less dependent on the opener. tag opener. .

+4
source

Source: https://habr.com/ru/post/919030/


All Articles