cancel
Showing results for 
Search instead for 
Did you mean: 

enabling or disabling an input field based on a dropdown box selection

Former Member
0 Kudos

hi

I am having a form in which I have a drop down box and an input field.

Based on the value selected from the dropdown the input fiels should be displayed.I have three options in the drop down.

No Search

Order Number

PO Search

Now if I select No search then the input field should be disabled, and on selecting either Order Number or Po number the input field should be enabled.

More over after selecting the Order Number and if the input field is left blank then a message should pop up saying "Order Number required"

the same is the case with the PO NUmber.

Can anybody help me in this issue.

thanks and regards

gopi krishna

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello,

Your dropdown has a parameter called "OnSelect". Create an Action and map it to this parameter.

Your input field has a parameter called "enabled". Add an attribute of type boolean to your context and map it to said parameter.

In your Action, mapped OnSelect of your dropdown simply check the value of the dropdown. If this value is "No Search" then set the boolean in the context to false, otherwise set it to true. This will give you your enabled/disabled functionality

You say also that the user must make an entry in the input field if it is enabled. On your Action "onOrderNumberSelect" (or whatever you've called it) simply check the value of the context attribute mapped to your input field. If it is null or its length is not greater than 0 then you know that no entry has been made. Alert the user.

Edit:

Of course when you're checking for null and length you only want to check if the input field is enabled (boolean context attribute is true). Also in wdDoInit set the boolean context attribute acordingly, either true or false as you require.

Regards,

Patrick.

Message was edited by: Patrick O'Neill

Former Member
0 Kudos

hi Patrick

Thanks for your response.

I am not able to get your solution clearly, can you explain me more clearly.

As I said earlier the error message should be based on the dropdown selection, either PO NUmber required or the Order Number required.

thanks and regards

gopi

Former Member
0 Kudos

Hi Gopi,

Arun has provided code that should work, it should help you a lot. The only change I'd make is to his onactionvalidate() method, here you would check the dropdown again to see if you wanted a PO Number of an Order Number and depending on this you would call reportfailure() with an appropriate text message.

Regards,

Patrick.

Former Member
0 Kudos

HI

My Actual problem is I have a dropdownbox it has 3 values and created on function for displaying error msg.

When iam selecting pirticular term then that selected term will be moving to the Errorfunction.

But here what happens only one value to taken for all dynamic values.

This is my function

Iam passing only 3 values 1,2,3.

But It always dispalys 2 only.

I think is there any problem in my function?.

public void checkMandatory( java.lang.String fieldName )

{

//@@begin checkMandatory()

IWDMessageManager messageMgr = this.wdThis.wdGetAPI().getComponent().getMessageManager();

Object attributeValue = this.wdContext.currentContextElement().getAttributeValue(fieldName);

IWDAttributeInfo attributeInfo = this.wdContext.getNodeInfo().getAttribute(fieldName);

if (attributeValue instanceof String) {

if (((String) attributeValue).length() == 0) {

String fieldLabel = this.wdContext.getNodeInfo().getAttribute(fieldName).getSimpleType().getFieldLabel();

messageMgr.reportContextAttributeMessage(this.wdContext.currentContextElement(),attributeInfo,IMessageSimpleErrors.MISSING_INPUT,

new Object[] { fieldLabel },

true);

}

}

//@@end

}

PLS guide me for this.

Answers (3)

Answers (3)

Former Member
0 Kudos

closing the thread

Former Member
0 Kudos

Let's assume you are using a DropDownByKey with value set


{
  /* key => value */ 
  "0" => "No Search",
  "1" => "Order Number",
  "2" => "PO Search 
}

(probably your keys are different, but you get the idea)

Let's assume the "selectedKey" property of the drop-down list is bound to an attribute "SelectedKey".

Define a read-only <b>calculated attribute</b> "InputEnabled" of type "boolean", bind the "enabled" property of the input field to this attribute. In the get-method of the calculated attribute, return the value

! ( "0".equals( wdContext.currentContextElement().getSelectedKey() ) )

This will enable the input field exactly if the selected entry is not "No Search".

To make the input field "mandatory" i.e. the user has to enter at least on character, create a DDIC type "NonEmptyString" based on type "string" with minimum length = 1, create an attribute of this type and bind the property "value" of the input field to this attribute.

Then the DDIC runtime will check for you that the entered value is not empty.

Armin

arun_srinivasan
Contributor
0 Kudos

hi,

1)map the enable property of the inputfield to value attribute of type boolean.

2)define the method for onselect for the dropdown

3)doinit()

{

wdcontext.currentcontextelement().set<valueattr bind to enabled property>(false/true);

}

4)

public void onActionoption(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

//@@begin onActionoption(ServerEvent)

String s1=new String();

String value=wdContext.currentContextElement().get<valueattribute mapped for dropdown>();

String str1=new String("nosearch");

if(value.equals(str1))

{

wdcontext.currentcontextelement().set<valueattr bind to enabled property>(false);

}

else

{

wdcontext.currentcontextelement().set<valueattr bind to enabled property>(true);

}

//@@end

}

5)create a button in the same view for validation whether user entered data r not

onactionvalidate()

{

if(wdcontext.currentcontextelement.getattibutename==null)

{

wdComponentAPI.getMessageManager().reportfailure("enter input");

}

}

hope this helps,

regards,

Arun