Blogs Blogs

Set Input Type required at run time

Platform: Sales and Service | 10 Comments 01.22.2010   adelao User_comment
Categories: Development

Hi all,

I have this situation: two widgets (both drop down list) on the same page, when a certain value is selected for the first widget I want to render the second one as required.
I tried with an extension on the first widget, but I could not set the “input type” property.

This is the extension I’ve used:

public class SetRequired extends com.epiphany.shr.ui.action.ccf.SendAllWidgetsValuesExtensionBase {

protected int execute(RuntimeFormInterface form, RuntimeFormWidgetInterface formWidget, HashMap params)
throws EpiException {

String m_val = (String)params.get(“fieldValue”);
if (m_val != null)
{
if (m_val.compareTo(“E7F1F4D0FFFFFFAC001EE2338B4C8043”) == 0)
{
form.getFormWidgetByName(“my_field2”).setProperty(“input type”,“required”);
}
}
System.out.println(form.getFormWidgetByName(“my_field2”).getProperty(“input type”));

return RET_CONTINUE;


}
}

“input type” is changed because the system.out.println prints “required” but when the form is saved the field is not considered mandatory.

Can anybody help?

Thanks

01.22.2010   Jason Balliet Oe-admin

Can you tell us which version ? There may be different ways to approach this based on what version you are implementing

01.22.2010   Jason Balliet Oe-admin

You could try changing your set property to the proper CCF version. So instead of

form.getFormWidgetByName(“my_field2”).setProperty(“input type”,“required”);

try

RuntimeFormWidgetInterface wgYourField = form.getFormWidgetByName(“YOUR_WIDGET_NAME”);

set_property(wgYourField, “input type”, “required”);

01.22.2010   Jason Balliet Oe-admin

You could try changing your set property to the proper CCF version. So instead of

form.getFormWidgetByName(“my_field2”).setProperty(“input type”,“required”);

try

RuntimeFormWidgetInterface wgYourField = form.getFormWidgetByName(“YOUR_WIDGET_NAME”);

set_property(wgYourField, “input type”, “required”);

01.26.2010   adelao User_comment

Hi all,

thanks for you suggestions, I’ve tried but it not working :-(
Anyway the version is 7.0.2

I’ve also tried using an EpiExtension, and it worked on FormRender, but when I tried to do the same on some user interface event like CCFRequest or UI Action it did not work, the “input type” was not set.

Don’t know what else to do.

01.26.2010   Jason Ihaia Oe-admin

Hi there,

The other thing you might want to try is rather than setting the input type, to manipulate the css class type to match other required fields. I know I had done this previously but it is not as straightforward as you might like. Let me know if that works, in the meantime, i will see if i can reserve some time to test it out.

Cheers,

Jason Ihaia

01.27.2010   adelao User_comment

Hi Jason,

thanks for the idea, unfortunately I’m a beginner with Epiphany and manipulate css class is not yet among my knowledge, so if you kindly tell me how can I do that I will be happy to try it.

Thanks

01.27.2010   Jason Balliet Oe-admin

One other thing to try as well. You said that the code worked as a form pre-render. Have you tried it as a widget pre-render ? Since you have a dependent dropdown, the widget may get a refresh (preRender event).

01.28.2010   adelao User_comment

Already tried that, actually the code is now on the “salve” widget preRender event, but it works only when the form is loaded in update mode and the “master” widget already has a value. Unfortunately the widget preRender for the “slave” widget doesn’t fire when the value is changed on the “master” widget, and the same code doesn’t work on the “master” widget onchanage event. As far as you know is there any way to force the preRenderWidget event? And of course there is a problem also when the form is loaded in new state, because the “master” widget doesn’t have a value yet.

It’s frustrating, on “master” widget onchange event I can change the value for the “slave” widget, I can change it’s label, hide it if I want, but I can not make it mandatory :-(

01.28.2010   Jason Ihaia Oe-admin

Hi there Adela,

Sorry I had not taken the time to look sooner as the solution is not too different than what you had tried. Essentially what you did by setting the type was in fact force the validation framework to add that to the list of required fields, but as you encountered, it did not provide the visual cue to the user. If you were to look at the properties of a widget through studio, outside of the property ‘input type’ you would also notice the additional property ‘label class’. This applies the appropriate css style to the widget – generally you would normally never touch this as it is handled through studio.
You need however to not only set the input type, but also the label class. This will the apply the css style to the widget. Following is an example:

RuntimeFormWidgetInterface myWidget = form.getFormWidgetByName("my_widget_name");
			myWidget.setProperty("input type","required");
			myWidget.setProperty("label class","epnyRequired");


Good luck with everything.

Cheers,

Jason Ihaia

02.04.2010   adelao User_comment

Hi Jason,

thanks, I’ve changed the “label class” property like you suggested, but it’s not working. The property changes (i did a getProperty after and write it to the console) but on form save, the widget is not required :-(
Is it anything else that I should do to let the form know that on save there is another widget to control?

Adela

If you wish to comment on this post, please register or login.