Making a control editable within a non editable form.

xavigepexavigepe Member Posts: 185
Hi. I have a non editable form, but I need one of its controls to be editable.

This is my solution:

By default the editable property in the form is set to false.

In the Onbeforeinput trigger of the control I write:
currform.editable := true;
mycontrol:=editable := true;

In the OnAfterValidate, OnInputChange and OnAfterInput triggers I wrtie:
currform.editable := false;

But if I enter the control and then leave it whithout making no change, none of the OnAfterValidate, OnInputChange and OnAfterInputChange triggers are activated and thus my form stills editable because I set its editable property a true in the OnBeforeInput trigger. How can I prevent this?.

Thanks,

Comments

  • krikikriki Member, Moderator Posts: 9,118
    Make the form Editable=TRUE, InsertAllowed=FALSE, DeleteAllowed=FALSE.
    Make all the fields, except the one you need Editable=FALSE.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Captain_DX4Captain_DX4 Member Posts: 230
    What about the OnDeactivate trigger for the control? I've not tried this, but perhaps you could test it? It should fire as soon as the control loses focus, regardless of whether or not input was made.

    Post back to let me know! Ta.
    Kristopher Webb
    Microsoft Dynamics NAV Developer
  • xavigepexavigepe Member Posts: 185
    Thanks for your idea Kriki, but what happens if the user decides to add new fields to the form?. Moreover, I need that for some users all the controls in the form should be editable, and for some users only one control will be editable.

    And about using the OnDeactivate trigger, it's not valid because this trigger only fires when you make Control.ACTIVATE = FALSE and I'm interested in a trigger which fires when you leave a control without making any change.


    Thanks for your ideas, I really apreciate them.
  • ara3nara3n Member Posts: 9,257
    Add a textbox with source expression a global variable. Onvalidate write you code to validate the field you want to update.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • krikikriki Member, Moderator Posts: 9,118
    xavigepe wrote:
    Thanks for your idea Kriki, but what happens if the user decides to add new fields to the form?. Moreover, I need that for some users all the controls in the form should be editable, and for some users only one control will be editable.
    -Users should not add fields! The developers should do that.
    -You can create a new Role and add that to users that may edit all controls.
    -In the "OnOpenForm"-trigger, you can check if a user belongs to that Role for current company (or all companies), and then make all the fields editable. Something like this (for DB-logons):
    recMemberOf.RESET;
    recMemberOf.SETCURRENTKEY("User ID","Role ID",Company);
    recMemberOf.SETRANGE("User ID",USERID);
    recMemberOf.SETRANGE("Role ID",'THE NEW ROLE');
    recMemberOf.SETFILTER(Company,'%1|%2',COMPANYNAME,'');
    blnAllFieldsEditable := recMemberOf.FIND('-');
    
    CurrForm."Field 1".EDITABLE(blnAllFieldsEditable);
    CurrForm."Field 2".EDITABLE(blnAllFieldsEditable);
    ...
    CurrForm."Field N".EDITABLE(blnAllFieldsEditable);
    
    Don't add your always editable field.
    When a new field is added, you just have to add it to this list.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.