Set focus to a specific field if criteria not met

irenegireneg Member Posts: 30
edited 2010-12-21 in Navision Attain
Hi there

I want to test on the modify event of a table if a value entered is valid, if not I want to set the focus back to that field containing the invalid value and don't allow user to continue, unless he cancel the entry. The error statement causes a rollback and the all will be lost, so this is not a solution.

Is the something in Navision that I can use similar to Foxpro's "setfocus" command?

Thanks

Irene
Irene Grassow

Answers

  • dkonedkone Member Posts: 59
    Hi,

    What happens if you put your validation code in the OnValidate trigger of the field ?

    Regards,

    dkone.
  • irenegireneg Member Posts: 30
    If the "Security Obtained" column contains "Legally in place" then the "Date Obtained" must contain a date. if the user enters over the "Obtained date" without changing or entering a value, the validate event does not take place. Also, I need to force the cursor to stay in the "Date Obtained" field of the record that is not valid.

    So, when the criteria is not met or the field is empty, a message must be displayed and the focus must stay on that field.

    Is this possible in Navision?

    Thanks
    Irene Grassow
  • dkonedkone Member Posts: 59
    Hi,

    You can Use Activate/Deactivate trigger on form to catch when user leaves a field.

    Something like this :
    "Security Obtained" - OnDeactivate 
    IF "Legally in place" THEN
    "Date Obtained".Activate
    
    "Date Obtained" - OnDeactivate
    Validation Code.
    

    But validation code should be on table not on form.

    Regards.

    Dkone.
  • irenegireneg Member Posts: 30
    I've tried the 'activate' command, but I'm getting an error "A variable is not a record".
    Date Signed - OnDeactivate
    if (Obtained = Obtained::"Legally in place") and ("Date Signed" = 0D) then
    begin
      message('you have to enter a date signed');
      "Date Signed".activate;
    end;
    

    I've placed all my other code on the table instead of the form, but cannot find a way to force a field to keep the focus.

    Thanks
    Irene Grassow
  • irenegireneg Member Posts: 30
    I've placed the CurrForm infront of the field.activate and that fixed the error, but the focus is still placed on the next field. it does not stay on the Date Signed field.

    Surely there must be something in Navision that allows you to manipluate the focus.

    Thanks
    Irene Grassow
  • dkonedkone Member Posts: 59
    You can put code that activates your field on each other OnActivate of the form.

    But if i where you, i'll do it in another way, more "Nav compliant".

    Trying to set and force focus is not the best solution : if you put your logic in the form what about an record created outside this form (by a report, a dataport,... ).

    Some other ways :
    - Put a boolean field "Validated" on your table that should be true to make the record ok. Put your validation code in the OnValidate of this field.
    - Look at the "DelayedInsert" property on a form, and put validation code on "OnInsert Trigger"
    - You can also look for 'mandatory fields' in this forum for further informations.
  • David_SingletonDavid_Singleton Member Posts: 5,479
    edited 2010-12-20
    ireneg wrote:
    I want to test on the modify event of a table if a value entered is valid, if not I want to set the focus back to that field containing the invalid value and don't allow user to continue, unless he cancel the entry.

    Irene

    Irene,

    Don't do this.

    Train the users to do it the Navision way. Ask them why they bought Navision in the first place. If they need FoxPro functionality they should have had a custom system developed in FoxPro.

    You are heading down a very long and dangerous path this way.

    <edit - added the quote to make it clear what I am replying to>
    David Singleton
  • dkonedkone Member Posts: 59
    Irene,

    Don't do this.

    I said something wrong ?

    Regards,

    dkone.
  • KowaKowa Member Posts: 923
    ireneg wrote:
    I've placed the CurrForm infront of the field.activate and that fixed the error, but the focus is still placed on the next field.
    That is normal behavior for the ACTIVATE command. Check the cursor run to find the field that is used prior to the one you want the cursor in. You have to activate that one, then the cursor will be in your "Date signed" field.
    Kai Kowalewski
  • David_SingletonDavid_Singleton Member Posts: 5,479
    dkone wrote:
    Irene,

    Don't do this.

    I said something wrong ?

    Regards,

    dkone.

    :?: :?: :?: :?:

    My post was addressed to Irene, not you.

    OK I edited my original post to make it more clear. Sorry for the confusion.
    David Singleton
  • irenegireneg Member Posts: 30
    I've decided to stick to Navision standards. I've added a new column, 'Error = boolean', which is populated on the OnModify trigger of the table. This way the form can indicate to the user which records are invalid and it is up to the user to fix them.

    Thanks for all you help!

    Irene
    Irene Grassow
  • David_SingletonDavid_Singleton Member Posts: 5,479
    ireneg wrote:
    I've decided to stick to Navision standards. I've added a new column, 'Error = boolean', which is populated on the OnModify trigger of the table. This way the form can indicate to the user which records are invalid and it is up to the user to fix them.

    Thanks for all you help!

    Irene

    =D> =D> =D> =D> =D> =D>

    Excellent decision.
    David Singleton
  • kitikkitik Member Posts: 230
    edited 2010-12-21
    ireneg wrote:
    I've decided to stick to Navision standards. I've added a new column, 'Error = boolean'

    Just a comment. Don't call your field "Error", give it some other name.
    If you call it Error, you wont be able to trow an ERROR on the table, because it confuses the field with the command.

    Salut!
    Laura Nicolàs
    Author of the book Implementing Dynamics NAV 2013
    Cursos Dynamics NAV (spanish) : http://clipdynamics.com/ - A new lesson released every day.
  • irenegireneg Member Posts: 30
    Thanks, I will change the field name. :D

    Irene
    Irene Grassow
Sign In or Register to comment.