Custom field validation  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Custom field validation

Postby pricerc » Fri Feb 01, 2019 8:50 pm

How can I restrict the entry into a custom text cell and/or otherwise validate entered custom data when the cell loses focus?

I would like to add some basic validation to a field, which means a) limiting the character set, and b) specifying some rules around what is and isn't valid.

I would then like to flag invalid data before the user clicks 'Save'.

I tried a RegularExpressionCellType, but it's not very user-friendly (it just ignores any edits that aren't valid, and reverts to the previous value - if you've just entered a 20 character field incorrectly, that could be annoying)
/Ryan

ERP Consultant,
Advanced ERP Limited, NZ
https://aerp.co.nz
User avatar
pricerc
Senpai
Senpai
 
Posts: 504
Joined: Mon Aug 10, 2009 12:22 pm
Location: Auckland, NZ
Topics Solved: 20

Re: Custom field validation

Postby SBarnes » Sun Feb 03, 2019 4:08 pm

Hi Ryan,

You could in the Set Up Before of the form hook onto the Grids changed event to get in ahead of Jiwa an example of this is below for a different grid, and show a message / throw an exception if the input was invalid

Code: Select all

jgRunLines.Change += jgRunLines_Change;


private void jgRunLines_Change(object sender, FarPoint.Win.Spread.ChangeEventArgs e)
      {
         //System.Diagnostics.Debugger.Break();
         string Key = null;
         string ColID = jgRunLines.ActiveSheet.Columns[e.Column].Tag.ToString();

         if (ColID == "NoItems" && e.Column == NoItemsColumn)
         {

            Key = jgRunLines.get_GridText("RecID", e.Row).ToString();
            JiwaDeliveries.JiwaDeliveryRunInstanceLine line = this._run.Lines[Key];
            decimal newitems = decimal.Parse(jgRunLines.get_GridText("NoItems", e.Row).ToString());
            if(newitems > 0)
            {
               line.NoItems = decimal.Parse(jgRunLines.get_GridText("NoItems", e.Row).ToString());
               this.UltraToolbarsManager1.Tools["ID_RecordSave"].SharedProps.Enabled = true;
               this.UltraToolbarsManager1.Tools["ID_RecordCancel"].SharedProps.Enabled = true;
               line.ChangeFlag = true;
               this._run.RecalcItemsAndOrders();
               this.utOrders.Value = this._run.NoOrders.ToString();
               this.utItems.Value = this._run.NoItems.ToString();
            }
            else
            {
                jgRunLines.set_GridText("NoItems",e.Row,line.NoItems.ToString());
               System.Windows.Forms.MessageBox.Show("Number must be greater than zero.");
            }

            
         }
         
      }


There is also EditModeOff which looks like

Code: Select all
private void fpSpread1_EditModeOff(object sender, System.EventArgs e)
{
     ListBox1.Items.Add("EditModeOff event fired!");
}



Also CustomFieldValue and CustomField also implement INotifyPropertyChanged so you could hook into this possibly as well.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1621
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 176

Re: Custom field validation  Topic is solved

Postby Scott.Pearce » Mon Feb 04, 2019 9:01 am

Use the MaskCellType. I have attached the documentation for the grid control that gives more information regarding this cell type (ftp://ftp.jiwa.com.au/FarPoint.Win.Spread.8.0.chm). I have also attached a sample plugin that masks the Description column of purchase order lines such that only 4 digits can be entered.

The basic code for a MaskCellType looks like this:

Code: Select all
      FarPoint.Win.Spread.CellType.MaskCellType maskcell = new FarPoint.Win.Spread.CellType.MaskCellType();
      maskcell.Mask = "####";
      maskcell.MaskChar = Convert.ToChar("#");
      purchaseOrderForm.LinesJiwaGrid.ActiveSheet.Columns["Description"].CellType = maskcell;
Attachments
Plugin PO Description Mask.xml
(33.89 KiB) Downloaded 82 times
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 743
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 221

Re: Custom field validation

Postby Mike.Sheen » Mon Feb 04, 2019 9:09 am

Note that to read downloaded CHM files you'll have to set the Unblock property of the downloaded CHM or all you'll see is blank pages.

Do this by right-clicking the downloaded file, select properties from the context menu, and then check the Unblock checkbox on the properties dialog.
Unblockdownloadedfile.PNG
Unblockdownloadedfile.PNG (20.62 KiB) Viewed 847 times
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2445
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 757

Re: Custom field validation

Postby pricerc » Mon Feb 04, 2019 4:30 pm

Aha! Thanks chaps.

So the mask was the trick I was looking for (although I dunno how I missed that and yet found Regex!).

I opted to use {Space} for the mask character, otherwise unused numbers are stored in the databases as whatever your mask character is.

But then I (eventually) figured out how that between 'Cell_EditorValueChanged', 'FormatCell' and 'ReadData', I could change the mask on one field, based on a selection in another.

I achieved this by using private fields to store a) the CustomFieldValue object for the values I was tracking, and b) the CellType objects for the related cells.
/Ryan

ERP Consultant,
Advanced ERP Limited, NZ
https://aerp.co.nz
User avatar
pricerc
Senpai
Senpai
 
Posts: 504
Joined: Mon Aug 10, 2009 12:22 pm
Location: Auckland, NZ
Topics Solved: 20


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 14 guests

cron