CA Service Management

  • 1.  Validation on SC

    Posted Jun 23, 2016 11:01 PM


    Hi Comunnity i hace a problem with two fields.

     

    One field is a Select with the options "Yes" and "No"

    The second field is a text field that ony needs to be filled if the select have the "Yes" option selected.

     

    So, if the form is begin subbmited i need to show an alert and focus the field. The problem is that i have a lot validations.... Is possible to use the validation system (this when focus the field with the error and red underline) for this? Or al most do it with Javascript but focus the field?

     

    Thanks!



  • 2.  Re: Validation on SC

    Posted Jun 24, 2016 03:01 PM

    Hello,

     

    I am not aware of a way to use the validation system to add a red border around the field but I have used this method.

    1. Set the Required attribute of the text field to "true".
    2. Add a JavaScript function to the form that does the following:
      1. Extract the value of the select field..."Yes" or "No".
      2. If the value is "Yes", use the ca_fdShowField function to dynamically display the text field on the form. The Required attribute is "true" so a value must be entered by the user to submit the request.
      3. If the value is "No", use the ca_fdHideField function to dynamically hide the text field so it does not appear on the form. The Required attribute will be ignored for hidden fields. You should also set the value of this field to null.
    3. Call the function in the onChange event of the select field.
    4. Also, call the function in the onLoad event of the form.

     

    Hope this helps,

    John

     

    If this reply correctly answered your question, please click the "Mark Correct" button so others can benefit from this response.



  • 3.  Re: Validation on SC

    Posted Jun 25, 2016 11:49 PM

    Hi Jhon, thanks for the answer! When you said:

    The Required attribute will be ignored for hidden fields. You should also set the value of this field to null.

    Do you mean that i need to put the "value" property of the field = "null"? I understand well?



  • 4.  Re: Validation on SC
    Best Answer

    Posted Jun 24, 2016 03:13 PM

    I recently learned how to use the hide, show, reset, and disable JS calls in Catalog forms and below is an example of how I now create my forms to handle what you are asking for.  You do not have to use the reset or disable functions like I do in my example but I like to prevent my users on checkout review from changing the data already saved by disabling the radio buttons.  I also like to reset the form if someone toggles back and forth between options clearing the previous data.

     

    Form name = Software_Install

    Form onLoad: ca_fd.js.RadioButtonCheckSoftware_Install()

    Radio Button Group

    Visual Label: Need Software Install on your PC?

    id=NeedSoftware

    required = True

    Radio button 1

    id = rb01

    value = Yes, needs software installed

    Visual Label: Yes

    Action: onclick show PC Name field

    onClick: ca_fdShowField('Software_Install','PCName');

    Radio button 2

    id = rb02

    value = No, does not need software installed

    Visual Label: No

    Action: onclick hide text field of PC Name and reset data

    onClick: ca_fdHideField('Software_Install','PCName');ca_fdResetFields('Software_Install',['PCName']);

    Text Field

    id=PCName

    Visual Label: PC Name

    Required = True

    Hidden = True

     

    Form Script

    {RadioButtonCheckSoftware_Install:function(){

    var isYesSelected = ca_fdIsSelectRadio('Software_Install','NeedSoftware','rb01');

    var isNoSelected = ca_fdIsSelectRadio('Software_Install','NeedSoftware','rb02');

    if (isYesSelected == 1) {

    ca_fdShowField('Software_Install','PCName');

    ca_fdDisableFields('Software_Install',['rb01','rb02']);}else{}

    if (isNoSelected == 1) {

    ca_fdHideField('Software_Install','PCName');

    ca_fdDisableFields('Software_Install',['rb01','rb02']);}else{}}}



  • 5.  Re: Validation on SC

    Posted Jun 26, 2016 01:00 PM

    Perfect! I'm doing using this way and works perfect! Thanks!