cancel
Showing results for 
Search instead for 
Did you mean: 

Input Restriction on simple datatype

Former Member
0 Kudos

Hi all

i have a Value Node in the application which is bind with Table UI element and is mapped with the Model Node(RFC Table). this node contains one field attribute as QUANTITY for which i want the input restriction like 1. max. value 999.99

2. three digits before and 2 digits after decimal point.

For this i have created a simple type with this definition which is based on Decimal data type.

My problems are that this checking takes place only on server trip caused by OnClick event of button and the error message it gives is very complicated to be understood by user.

is there any way to check this restriction at client side?

is there any way to customize the error message?

please suggest me a way out.

Deepak

Accepted Solutions (1)

Accepted Solutions (1)

sanyev
Active Participant
0 Kudos

Hi Deepak,

Validating actions will do a data type check. If you have configured the data type as per your requirement then upon execution of a validating action your constrains will be checked. and error if any will be displayed.

Unfortunately there is no way to do this at the client side with out a server round trip.

You can also do the error checking yourself and display a message to the user if there are some errors. The below mentioned code does that. You can include that in your action hadler. The code below will trigger the frameworks validation mechanism to show the error fields and give a corrective message.

IWDMessageManager msgMgr =
	wdComponentAPI.getMessageManager();
	msgMgr.reportContextAttributeMessage(
            wdContext.nodeStudent().currentStudentElement().getAttributePointer("name"),
	IMessageActionValidationTest.MISSING_INPUT, new Object[] {"Name"});

If you execute the above code in your action handler then the inputfield bound to the attribute name will be highlighted in error. The message with key MissingInput which is there in the message pool will be shown as the error explanation message.

You can go throuth this tutorial on form validation. https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/60db527d-7be4-2a10-0283-e915cfb1...

If you would like to set a length limitation to an attribute you can set the Min or Max length for that attribute and the default validation mechanism will take care of the validation.

You can write the code in wdDoInit() for setting length limitation.

wdContext().nodeData().getNodeInfo().getAttribute("name").getModifiableSimpleType().setMinLength(5);

Hope this helps.

Regards,

Sanyev

Former Member
0 Kudos

Hi Sanyev

thanks for immediate reply.

actually the check for the minimum/maximum length on client side is carried out only for the the String data type or simple types based on String data type. i have issue with decimal data type for which no such length restriction is checked at client side.

The error message which is thrown after validation check is complicated says

"Decimal value 12345 is too large for total Digits 6 and fractionDigits 2". (since i have defined simple type with max 6 digits in format 000.00). This is very complicated message and is not suitable to be displayed for end user

Error handling with code is not economical since it has to check each line item of the table. and on worst case no of line items may go up to 31(no of days), each line item having 5 such fields that means it will take 155 checks!!!

so i wanted solution like built in client side validation if available or a way to change this error message.

thanks

Deepak

sanyev
Active Participant
0 Kudos

Hi Deepak,

As you have mentioned client side validation is not available for all data types. Even if you some how configure the validation at client side there is no way to give a proper error message. So you will have to do the validation yourself.

Who ever does the validation will have to check all the 155 fields even if it is you or the framework. So the number of fields to be validated doesn't matter.

The code that I have mentioned in the above post can be used to highlight the error fields and give an appropriate message. The document that is given in the above post is very useful for validation. Validating 155 fields is not a very performance intensive step. If you see the code for rendering a table each field in a table goes through multiple levels of validation before it is rendered every time. So I guess doing the validation at your side is not a bad choice.

Regards,

Sanyev

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Deepak,

There is no way to change/customize this error message if you are using simple type.

Regards

Narendra