Need to provide dynamic initial values for OOB form widget

tantony
Mega Guru

I have embedded OOB form widgets in my widget. 

HTML :

<div >
<button ng-click="c.onEditForm('widget-form',{'table': c.data.table,'sys_id': -1})" type="button" class="btn btn-success btn-md pull-right pad">Add your item</button>
</div>

Client controller function:

c.onEditForm = function(widgetId, widgetInput) {
spModal.open({
title: 'Add your item',
widget: widgetId, 
widgetInput: widgetInput || {}
}).then(function(){
console.log('widget dismissed');
c.server.update();
}); 
}

This works and let me add new records. But I want two fields  dynamically populated with initial values in the empty form displayed.I could not find documentation for what keys goes into  'widgetInput'  parameter for spModal.open(). As far as I have seen, it is only 'table','sys_id' and 'view '. Is it possible to give default values for field when the spModal is opened?

1 ACCEPTED SOLUTION

tantony
Mega Guru

I could get this working by cloning OOB widget-form . It was a scoped application.What I wanted was to call the form widget inside a spModal in the parent widget and give initial dynamic values for three fields of the form and make the three fields read only. The field values were passed from parent widget  to embedded cloned form widget via the 'shared' parameter of spModal.open() as documented here.

c.onEditForm = function(widgetId, widgetInput, initialValues) {
spModal.open({
title: 'Edit your potluck item ',
widget: widgetId, // cloned form widget id
widgetInput: widgetInput || {}, //keys are table , sys_id= '-1', view
shared: initialValues      // keys are fields which needed initial values
}).then(function(){
    console.log('widget dismissed');


});
}

The 'shared' json object was accessible in the client script of  cloned embedded form widget.

View solution in original post

4 REPLIES 4

Naveen4
Kilo Guru

Hi,

are you looking to give the values to the form  you can go through ng-model  in the html section of the widget.

 

Thanks,Naveen

tantony
Mega Guru

The page is complex with three levels of embedding. I want the form widget to be opened inside a modal window by clicking a button with ng-click directive. That will make the page less cluttered.

tantony
Mega Guru

I could get this working by cloning OOB widget-form . It was a scoped application.What I wanted was to call the form widget inside a spModal in the parent widget and give initial dynamic values for three fields of the form and make the three fields read only. The field values were passed from parent widget  to embedded cloned form widget via the 'shared' parameter of spModal.open() as documented here.

c.onEditForm = function(widgetId, widgetInput, initialValues) {
spModal.open({
title: 'Edit your potluck item ',
widget: widgetId, // cloned form widget id
widgetInput: widgetInput || {}, //keys are table , sys_id= '-1', view
shared: initialValues      // keys are fields which needed initial values
}).then(function(){
    console.log('widget dismissed');


});
}

The 'shared' json object was accessible in the client script of  cloned embedded form widget.

Hello, how did you setValue from shared for the field in the form widget? I cannot do it via g_form.setValue(), recieving the error:(