Disabling a field when some condition is true

aliennavaliennav Member Posts: 449
Can we diable a field when some condition is satisfied?
Suppose i have checked a check box ,now i want some text field to be non- editable.
What can be done for it?

Comments

  • AlbertvhAlbertvh Member Posts: 516
    Hi

    in the OnAfterValidate of the check box
    CurrForm.MyField.Enabled := TRUE;
    IF Disable THEN
      CurrForm.MyField.Enabled := FALSE;
    
    

    Hope this helps :)
  • kinekine Member Posts: 12,562
    And it is table form or card form?
    Do not forget to refresh editable property when record is changed (OnAfterGetCurrRecord).
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • aliennavaliennav Member Posts: 449
    Albertvh wrote:
    Hi

    in the OnAfterValidate of the check box
    CurrForm.MyField.Enabled := TRUE;
    IF Disable THEN
      CurrForm.MyField.Enabled := FALSE;
    
    

    Hope this helps :)

    Coool
    It's working
  • JaanuJaanu Member Posts: 44
    Hi Kine Sir,

    I have the above issue with Currform.Field.Enabled property based on condition. And my code as

    IF "Item Type" = "Item Type"::"Filter Plate" THEN BEGIN
    CurrForm."Instrument Type".ENABLED(FALSE);;
    CurrForm.Range.ENABLED(FALSE);
    CurrForm.Body.ENABLED(FALSE);
    CurrForm."Process Connection".ENABLED(FALSE);
    CurrForm.Model.ENABLED(FALSE);
    CurrForm.BoreDia.ENABLED(FALSE);
    CurrForm.RodDia.ENABLED(FALSE);
    CurrForm."Stoke length".ENABLED(FALSE);
    CurrForm.Kwatts.ENABLED(FALSE);
    CurrForm."BOM Door Cylinder".ENABLED(FALSE);
    CurrForm."Plate Shifter".ENABLED(FALSE);
    CurrForm."Main Cylinder".ENABLED(FALSE);
    CurrForm."Side Cylinder".ENABLED(FALSE);
    CurrForm."Valves Type".ENABLED(FALSE);
    CurrForm."Valves Category".ENABLED(FALSE);
    CurrForm.PLC.ENABLED(FALSE);
    CurrForm."OP Panel".ENABLED(FALSE);
    CurrForm.MCC.ENABLED(FALSE);
    CurrForm.LCS.ENABLED(FALSE);
    CurrForm.RLC.ENABLED(FALSE);
    CurrForm.Gladding.ENABLED(FALSE);
    CurrForm.MoC.ENABLED(FALSE);
    END ELSE
    IF "Item Type" = "Item Type"::"Filter Cloth" THEN BEGIN
    CurrForm."Instrument Type".ENABLED(FALSE);
    CurrForm.Range.ENABLED(FALSE);
    CurrForm.Body.ENABLED(FALSE);
    CurrForm."Process Connection".ENABLED(FALSE);
    CurrForm.BoreDia.ENABLED(FALSE);
    CurrForm.RodDia.ENABLED(FALSE);
    CurrForm."Stoke length".ENABLED(FALSE);
    CurrForm.Kwatts.ENABLED(FALSE);
    CurrForm."BOM Door Cylinder".ENABLED(FALSE);
    CurrForm."Plate Shifter".ENABLED(FALSE);
    CurrForm."Main Cylinder".ENABLED(FALSE);
    CurrForm."Side Cylinder".ENABLED(FALSE);
    CurrForm."Valves Type".ENABLED(FALSE);
    CurrForm."Valves Category".ENABLED(FALSE);
    CurrForm.PLC.ENABLED(FALSE);
    CurrForm."OP Panel".ENABLED(FALSE);
    CurrForm.MCC.ENABLED(FALSE);
    CurrForm.LCS.ENABLED(FALSE);
    CurrForm.RLC.ENABLED(FALSE);
    CurrForm.Gladding.ENABLED(FALSE);
    CurrForm.MoC.ENABLED(FALSE);
    END ELSE
    IF "Item Type" = "Item Type"::Cylinder THEN BEGIN
    CurrForm."Instrument Type".ENABLED(FALSE);
    CurrForm.Range.ENABLED(FALSE);
    CurrForm.Body.ENABLED(FALSE);
    CurrForm."Process Connection".ENABLED(FALSE);
    CurrForm.Kwatts.ENABLED(FALSE);
    CurrForm."BOM Door Cylinder".ENABLED(FALSE);
    CurrForm."Plate Shifter".ENABLED(FALSE);
    CurrForm."Main Cylinder".ENABLED(FALSE);
    CurrForm."Side Cylinder".ENABLED(FALSE);
    CurrForm."Valves Type".ENABLED(FALSE);
    CurrForm."Valves Category".ENABLED(FALSE);
    CurrForm.PLC.ENABLED(FALSE);
    CurrForm."OP Panel".ENABLED(FALSE);
    CurrForm.MCC.ENABLED(FALSE);
    CurrForm.LCS.ENABLED(FALSE);
    CurrForm.RLC.ENABLED(FALSE);
    CurrForm.Gladding.ENABLED(FALSE);
    CurrForm.MoC.ENABLED(FALSE);
    CurrForm.Type.ENABLED(FALSE);
    CurrForm.Tickness.ENABLED(FALSE);
    CurrForm."Discharge Type".ENABLED(FALSE);
    CurrForm.Varient.ENABLED(FALSE);
    END ELSE
    IF "Item Type" = "Item Type"::"Power Pack" THEN BEGIN
    CurrForm."Instrument Type".ENABLED(FALSE);
    CurrForm.Range.ENABLED(FALSE);
    CurrForm.Body.ENABLED(FALSE);
    CurrForm."Process Connection".ENABLED(FALSE);
    CurrForm."Valves Type".ENABLED(FALSE);
    CurrForm."Valves Category".ENABLED(FALSE);
    CurrForm.PLC.ENABLED(FALSE);
    CurrForm."OP Panel".ENABLED(FALSE);
    CurrForm.MCC.ENABLED(FALSE);
    CurrForm.LCS.ENABLED(FALSE);
    CurrForm.RLC.ENABLED(FALSE);
    CurrForm.Gladding.ENABLED(FALSE);
    CurrForm.MoC.ENABLED(FALSE);
    CurrForm.Type.ENABLED(FALSE);
    CurrForm.Tickness.ENABLED(FALSE);
    CurrForm."Discharge Type".ENABLED(FALSE);
    CurrForm.Varient.ENABLED(FALSE);
    CurrForm.BoreDia.ENABLED(FALSE);
    CurrForm.RodDia.ENABLED(FALSE);
    CurrForm."Stoke length".ENABLED(FALSE);
    CurrForm.Model.ENABLED(FALSE);
    CurrForm.Size.ENABLED(FALSE);
    END ELSE
    IF "Item Type" = "Item Type"::Valves THEN BEGIN
    CurrForm."Instrument Type".ENABLED(FALSE);
    CurrForm.Range.ENABLED(FALSE);
    CurrForm.Body.ENABLED(FALSE);
    CurrForm."Process Connection".ENABLED(FALSE);
    CurrForm.PLC.ENABLED(FALSE);
    CurrForm."OP Panel".ENABLED(FALSE);
    CurrForm.MCC.ENABLED(FALSE);
    CurrForm.LCS.ENABLED(FALSE);
    CurrForm.RLC.ENABLED(FALSE);
    CurrForm.Gladding.ENABLED(FALSE);
    CurrForm.MoC.ENABLED(FALSE);
    CurrForm.Type.ENABLED(FALSE);
    CurrForm.Tickness.ENABLED(FALSE);
    CurrForm."Discharge Type".ENABLED(FALSE);
    CurrForm.Varient.ENABLED(FALSE);
    CurrForm.BoreDia.ENABLED(FALSE);
    CurrForm.RodDia.ENABLED(FALSE);
    CurrForm."Stoke length".ENABLED(FALSE);
    CurrForm.Model.ENABLED(FALSE);
    CurrForm."BOM Door Cylinder".ENABLED(FALSE);
    CurrForm."Plate Shifter".ENABLED(FALSE);
    CurrForm."Main Cylinder".ENABLED(FALSE);
    CurrForm."Side Cylinder".ENABLED(FALSE);
    CurrForm.Kwatts.ENABLED(FALSE);
    CurrForm.Pressure.ENABLED(FALSE);
    END ELSE
    IF "Item Type" = "Item Type"::"PLC Panel" THEN BEGIN
    CurrForm."Instrument Type".ENABLED(FALSE);
    CurrForm.Range.ENABLED(FALSE);
    CurrForm.Body.ENABLED(FALSE);
    CurrForm."Process Connection".ENABLED(FALSE);
    CurrForm.Gladding.ENABLED(FALSE);
    CurrForm.MoC.ENABLED(FALSE);
    CurrForm.Type.ENABLED(FALSE);
    CurrForm.Tickness.ENABLED(FALSE);
    CurrForm."Discharge Type".ENABLED(FALSE);
    CurrForm.Varient.ENABLED(FALSE);
    CurrForm.BoreDia.ENABLED(FALSE);
    CurrForm.RodDia.ENABLED(FALSE);
    CurrForm."Stoke length".ENABLED(FALSE);
    CurrForm.Model.ENABLED(FALSE);
    CurrForm."BOM Door Cylinder".ENABLED(FALSE);
    CurrForm."Plate Shifter".ENABLED(FALSE);
    CurrForm."Main Cylinder".ENABLED(FALSE);
    CurrForm."Side Cylinder".ENABLED(FALSE);
    CurrForm."Valves Type".ENABLED(FALSE);
    CurrForm."Valves Category".ENABLED(FALSE);
    CurrForm.Size.ENABLED(FALSE);
    CurrForm.Kwatts.ENABLED(FALSE);
    END ELSE
    IF "Item Type" = "Item Type"::Frame THEN BEGIN
    CurrForm."Instrument Type".ENABLED(FALSE);
    CurrForm.Range.ENABLED(FALSE);
    CurrForm.Body.ENABLED(FALSE);
    CurrForm."Process Connection".ENABLED(FALSE);
    CurrForm.Type.ENABLED(FALSE);
    CurrForm.Tickness.ENABLED(FALSE);
    CurrForm.Varient.ENABLED(FALSE);
    CurrForm.BoreDia.ENABLED(FALSE);
    CurrForm.RodDia.ENABLED(FALSE);
    CurrForm."Stoke length".ENABLED(FALSE);
    CurrForm.Model.ENABLED(FALSE);
    CurrForm."BOM Door Cylinder".ENABLED(FALSE);
    CurrForm."Plate Shifter".ENABLED(FALSE);
    CurrForm."Main Cylinder".ENABLED(FALSE);
    CurrForm."Side Cylinder".ENABLED(FALSE);
    CurrForm."Valves Type".ENABLED(FALSE);
    CurrForm."Valves Category".ENABLED(FALSE);
    CurrForm.Size.ENABLED(FALSE);
    CurrForm.PLC.ENABLED(FALSE);
    CurrForm."OP Panel".ENABLED(FALSE);
    CurrForm.MCC.ENABLED(FALSE);
    CurrForm.LCS.ENABLED(FALSE);
    CurrForm.RLC.ENABLED(FALSE);
    CurrForm.Make.ENABLED(FALSE);
    CurrForm.Pressure.ENABLED(FALSE);
    CurrForm.Kwatts.ENABLED(FALSE)
    END ELSE
    IF "Item Type" = "Item Type"::Instruments THEN BEGIN
    CurrForm.Type.ENABLED(FALSE);
    CurrForm.Tickness.ENABLED(FALSE);
    CurrForm."Discharge Type".ENABLED(FALSE);
    CurrForm.Varient.ENABLED(FALSE);
    CurrForm.BoreDia.ENABLED(FALSE);
    CurrForm.RodDia.ENABLED(FALSE);
    CurrForm."Stoke length".ENABLED(FALSE);
    CurrForm.Model.ENABLED(FALSE);
    CurrForm."BOM Door Cylinder".ENABLED(FALSE);
    CurrForm."Plate Shifter".ENABLED(FALSE);
    CurrForm."Main Cylinder".ENABLED(FALSE);
    CurrForm."Side Cylinder".ENABLED(FALSE);
    CurrForm."Valves Type".ENABLED(FALSE);
    CurrForm."Valves Category".ENABLED(FALSE);
    CurrForm.Size.ENABLED(FALSE);
    CurrForm.PLC.ENABLED(FALSE);
    CurrForm."OP Panel".ENABLED(FALSE);
    CurrForm.MCC.ENABLED(FALSE);
    CurrForm.LCS.ENABLED(FALSE);
    CurrForm.RLC.ENABLED(FALSE);
    CurrForm.Gladding.ENABLED(FALSE);
    CurrForm.MoC.ENABLED(FALSE);
    CurrForm.Kwatts.ENABLED(FALSE);
    CurrForm.Pressure.ENABLED(FALSE);
    END;

    Its not working properly when i do enter item type or when i click on next rec view.
    Each time I choose the rec from list to card, only when i run it again it works fine.
    Is it possible to make work on all cases?

    Thanks & Regards,
    Jaanu
  • kinekine Member Posts: 12,562
    1st: "opening" 7 years old topic is not much optimal... ;-)
    2nd: you are showing the code to set the properties, but the problem is "from where you call this code". And you are not mention this...
    3rd: what about using Case command instead of the not nice if-then-else-if-then-else chain? ;-)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • JaanuJaanu Member Posts: 44
    edited 2014-07-15
    OK Sir. I will change my code. Since i'm a beginner in coding, i started with if else.

    I Wrote the above code in Item type field OnValidate & also in On AfterGetCurrRecord.
  • kinekine Member Posts: 12,562
    Another thing: you are setting everywhere FALSE. Where are you enabling them?

    One TIP: create function like SetControlEnabled(param), put the code there, and from the Case just call the function with correct parameter. This Copy&Paste code is not good. Do not forget to make the code reusable...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • JaanuJaanu Member Posts: 44
    For each type, few fields have to be disabled.
    Ok sir. I will try as you said.


    Thanks,
    Jaanu
  • kinekine Member Posts: 12,562
    Please, do not do what I said, but think about it. It seems, like you want some fields to disable, and some enable. But everywhere in your code there is parameter FALSE. Where is call with TRUE? You must ENABLE the fields somewhere, else you disable them all when going between records...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • JaanuJaanu Member Posts: 44
    thank you sir. I have done with my task. :) i left the fields which has to be enabled on type option.
  • vivek4121vivek4121 Member Posts: 165
    Its not working in my case as well..
  • tothszabolcstothszabolcs Member Posts: 21
    You should open a new topic for your case, others will help you with it.
Sign In or Register to comment.