cancel
Showing results for 
Search instead for 
Did you mean: 

Required and Non-Required Input Fields Together

Former Member
0 Kudos

Hello-

I have a total of 6 input fields. The first of them is required, so I labeled it so. The rest are not required. However, I do not want the user to be able to enter anything in the next 5 input fields until they have entered information in the first input field. Is there any way to do so? Maybe somehow making the last 5 Read-Only until the required info is entered? Or graying them out somehow? Anything? Thanks for the help!

(As always, points will be awarded)

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Kathleen,

if u want all other fields except first field to be read only..

1) create one context variable of type boolean.

2) Bind that variable to read only property of the all other inputfields that u want to make readonly.

3) And set that context variable value to TRUE in "init" method.

4) make that value as FALSE in onEnter action of first input field....

so that, other fields cannot accept any data..it will greyed up..when u press enter in the first field, then only other will change to accept the data...

hope this helps you....

feel free to ask any help further

regards

-


sunil

Former Member
0 Kudos

Ahhh this makes sense! Thank you! One or two questions that, syntax wise. So if I gave my variable the name ReadOnly (just to keep things simple!) in the init method, I can't just do: ReadOnly = true;

How does the syntax work? (I am not a java person! clearly!) And then I assume it will work the same way in my onEnter...

So in the view where I want the user to enter the required info, I first created a context variable called ReadOnly. I assigned ReadOnly to the read only property of all other input fields. Then(in the same view) I went into the init method and did: boolean ReadOnly = true;

Then in the onEnter(), i did boolean ReadOnly = false;

This did not quite work, so I know I am doing something wrong! Thanks for any help!!

Thanks for the additional help!

Message was edited by: Kathleen Reilly

Former Member
0 Kudos

Another possibility: Create a <b>calculated </b>context attribute "FieldsReadOnly", type=boolean.

Bind the "readOnly" property of all non-required input fields to that context attribute.

In the generated getFieldsReadOnly-method, check the value of the required field and return true, if it is empty.

The only drawback is that you need a server roundtrip to recalculate the attribute value. The user either has to press ENTER in the required field or press an explicit button to achieve this. In both cases you must assign some (empty) action to the corresponding event.

Code:

boolean getFieldsReadOnly(...)
{
  /* Let "RequiredValue" be the context attribute storing the required field's value */
  String value = wdContext.currentContextElement().getRequiredValue();
  return value == null || value.trim().length() == 0;
}

Armin

Just remarked this was already Valery's proposal, except I would recommend using property "readOnly" instead of "enabled".

Former Member
0 Kudos

Hi Kathleen,

1. Let's say you have created a context variable of type boolean. Let's say you have named it "ReadOnly".

2. Bind this variable to the readOnly property of the inputfields that you want to enable/disable.

3. Then in the wdDoInit() method, write this code:


wdContext.currentContextElement().setReadOnly(true);

4. Then in the onEnter eventHandler of the first inputfield, write this code:


wdContext.currentContextElement().setReadOnly(false);

Regards,

Satyajit.

Former Member
0 Kudos

Ahhh this makes sense! Thank you! (I need to learn syntax!)

I am so close to what I want now, but one piece of the puzzle I left out: The very first input field is date selection, and the user has to select a Sunday. If they don't, an error message is displayed telling them to choose a Sunday. However, with the way I have the code now (after entering the code you offered me), no matter what day they choose (Sunday or not), the other input fields are changing from read only to not read only. So if they do not enter a Sunday, how do I re-set my Read-Only variable to remain read-only?

Does this make sense? Sorry, a little confusing!

Former Member
0 Kudos

Never mind, that was a lot easier than I thought! Thanks for all the help!

Former Member
0 Kudos

Hi,

Have you figured this out already? Incase you haven't, then here's how to do it in the eventhandler:

Say you have declared a context attribute DateField of type date and bound it to your first inputfield.


Date d = wdContext.currentContextElement().getDateField();
Calendar cal = new GregorianCalendar();
cal.setTime(d);
		
if (cal.get(Calendar.DAY_OF_WEEK) == 1){
  wdContext.currentContextElement().setReadOnly(false);			
}

Regards,

Satyajit.

Answers (2)

Answers (2)

former_member193726
Active Participant
0 Kudos

Hi Kathleen,

One small update rather I can call it as verification.

In your input field UI Element you must be having a property called state. Did you try changing it to required?. If you do this, you can by-pass the code and your target is acheived.

Regards,

Rekha Malavathu.

Former Member
0 Kudos

Kathleen,

The best option would be to have these fields on different views and navigate between views...

You can to create onEnter action handler for every required, bind "enabled" property of optional InputFields to boolean context attributes, and switch them to true/false in action handler depending on whether or not all required field populated. The drawback is that user have to press ENTER at least at latest field. Or you may create explicit "Apply" button.

VS

Former Member
0 Kudos

Oh darn, that's exactly what I was hoping to avoid doing!

Former Member
0 Kudos

Kathleen,

No other way -- something like JavaScript "onchange" events are not propagated to server.

VS