CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> Tips & Solutions

 HOT TIP: Editable Grid Add Row Button + Default Value + No Blank Empty Rows!

Print topic Send  topic

Author Message
FunkDaddy

Posts: 10
Posted: 03/26/2009, 7:04 PM

HOT TIP: Editable Grid Add Row Button + Default Value + No Blank Empty Rows!

So you want to have a editable grid just like the example shown in Example Pack 1 called "Editable Grid with 'Add Row' button (http://examples.codecharge.com/ExamplePack/EditableGridAddButton/EditableGridAddButton.php), right?

Well, the example works, however, if you want to have a grid that contains a field with a default value you will run into a very common problem found by many other CCS users... your database table will populate with a bunch of empty rows (or records) whenever you submit the form. This happens, eventhough you think you are only submiting one row (or record) based on the illusion that you may have only clicked on the "Add Row" button once, filled out the record, then pressed the submit button.

I solved the problem.. I now have an editable grid, with a "Add Row" button, that allows a field to havea default value (I used a parameter value for mine), without populating the database with empty fields!

Step 1: Follow the Example Pack 1 to implement the "Add Row" button in Editable Grid (it works, despite the fact I had to try 3 times)

Step 2: Entert the following custom code in the "Before Build Insert" Event of your Editable Grid form:

if ($FormName->YourFieldName->GetValue()=='') {

//empty field therfore we don't want to save this record
$FormName->InsertAllowed = false;

} else {

//record is recorded,

$FormName->InsertAllowed = true;}

STEP 3: IMPORTANT: Now please note that the "YourFieldName" should be a field on the form that DOES NOT contain your default value. Also, make sure you do NOT choose the "YourFieldName" as a field that has an autoincrement setting, as it will always have a value (in theory).

Step 4: In the field properties of the field you wish to have pre-populated with a default value everytime you click the "Add Row" button, put in your default value. For example, in my case, I went ahead and imply typed CCGetParam("ItemID") so that all my new records in the editable grid would have the correct "ItemID" as soon as I pressed the "Add Row" button.

Step 5: Done!

So, here's why I posted this here... many other folks have posted varying solutions. The best one that I found (and one that led me to solve this problem) was this one, posted by Jacem: http://forums.yessoftware.com/posts.php?post_id=104083

I cut down his code a bit and reworded the field names so it was cleared for newbies like me exactly what to replace names with in the equivalent of my own forms. The missing element to his/her post was the instruction I highlight in STEP 3.... it holds the key to preventing empty records from being added to your database.

So the truth is Jacem should take all the credit for this solution. I merely am pointing out a more dumbed down explanation, since I spent hours trying to get this to work.

Here is another post regarding the issue... I'm just posting it here because I find it helpful to view similar posts to see if they match my problem.

http://forums.yessoftware.com/posts.php?post_id=78061&s...d=insertallowed

Good night & good luck!

View profile  Send private message
FunkDaddy

Posts: 10
Posted: 03/30/2009, 1:03 PM

Update... and corrections:

OK... so today I went ahead and tried to prevent the entry of empty fields in a editable grid that contained one field with a preset default value (which I set in the properties windows in CCS by simply setting a CCGetParm("Parameter1") ... it didn't work. The dam grid kept submitting empty rows because of the one field that had the default value.

So I tried using my solution as shown above, but to no avail. Now, this time I was doing something slightly different than the example in my previous post (to which I am now replying)... I was not using the "Add Row" button at all, rather I was simply using the standard Editable Grid Builder.

Anyhow, not sure why it wasn't working.... I did however find the answer in another posting. Here it is:

If you use the same code from post above....

if ($FormName->YourFieldName->GetValue()=='') {

//empty field therfore we don't want to save this record
$FormName->InsertAllowed = false;

} else {

//record is recorded,

$FormName->InsertAllowed = true;}


It will not work in the Editable Grid Events....

None of these work....
- On Validate
- On Validate Row
- Before Submit
- After Submit
- Before Build Insert
- Before Execute Insert

Instead if I put these lines in the field's "On Validate" event it just works!

Well, I'll have to remember this one!

THANK YOU!

Credit is due to the following post for this:
http://forums.yessoftware.com/posts.php?post_id=96973&s...d=InsertAllowed+

Thanks aslsondrio you saved me precious time!
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright 2003-2004 by UltraApps.com  and YesSoftware, Inc.