Results 1 to 4 of 4

Thread: [Answers] Validation

Threaded View

  1. #1
    Lianja MVP
    Join Date
    Dec 2012
    Location
    Croatia, Zagreb
    Posts
    1,135

    [Answers] Validation

    Grids do not currently 'Inherit dictionary rules' - Form and Canvas Sections can (off by default, check the Attribute to enable).
    Your validation check will be evaluated when the data is saved to the table and the update rejected if the validation fails, but the error message will not be shown in the Grid.



    Have you tried just calling your validation routine from the 'Validation' of the Grid column (double-click column header to access Attributes) where the users input the filter commands?
    Use "{}" to pass the character value entered in the Grid column to your routine, e.g. valudf function in loaded script library or valudf.prg:
    Validation: valudf("{}")
    If the routine returns .F., the 'Validation error message' will be displayed and the column value will be blanked out (Add) or set to its previous value (Edit).



    The Validation attribute on the textbox itself expects an expression which will be evaluated to return .T. (valid) or .F. (invalid and Error message attribute contents will be displayed or default message).

    The 'Valid When' method on the Canvas Section is called when changes have been made to data in the Section and you move to another record. This allows you to do a 'batch' validation of more than one item in the Section in one go if you don't want to do each individually as you move between them.



    Validation is not called for each keypress. It is called when you attempt to transfer focus away from the textbox with tab, enter or mouse click.



    Q:
    When the mandatory field has the focus, how I can prevent the user moves leaving the field blank or enter an invalid data?
    A:
    You need to use the "onbeforeupdate" delegate to prevent the field from being left blank. As I mentioned in another thread, this is called when the user attempt to save the record.



    Both the "Valid when" and the "Before update" can return .f. to prevent the data being updated. Obviously you can provide the user with some feedback using Lianja.showMessage() or something similar.



    You need to check the "Mandatory input" attribute on fields. This will prevent the field being saved when it is empty. This does not appear be available for grid columns.
    For a grid you need to use the "Valid when" delegate which will be called when a row is going to be updated. Inside this delegate you can then check various logical conditions of data that has been input.
    If you want to reject the input then the delegate function should return .f. otherwise return .t. if all is ok.



    ​All topics in [Answers] alphabetically:http://www.lianja.com/community/show...ll=1#post12352
    Last edited by josipradnik; 2016-03-03 at 03:36.

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Journey into the Cloud
Join us