CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 [RESOLVED] Setting default for text field in editable grid without ccs saving blank records from the blank rows

Print topic Send  topic

Author Message
jacem

Posts: 87
Posted: 02/10/2009, 9:59 PM

Not sure if this is a bug or a limitation in implementation of the CCS interface model.

If I set a text control in a row in an editable grid to have a default value for blank/new row, then I don't expect CCS to try and save every blank row as a new record just because it has a default value. If the user hasn't entered data into any of the other fields on a blank row nor changed the default value of the control in question then surely the user isn't considered to be wanting to add a new record? CCS thinks because there is a 'default' value in the control that it should be considered a new row to be inserted into the table. In this example the user has submitted the form becuase they have simply changed values in existing records / rows but not added any new row data.

I have reviewed the PHP forum on this issue -seems quite a few users have this issue.

CCS behaves as expected if there are no defaults: it only saves blank/new rows that have had the suer enter data into them. As soon as you set one of the fields to have a default the number of blank/new rows is attempted to be saved when the page is submitted.

Am I barking up the wrong tree?

View profile  Send private message
damian

Posts: 838
Posted: 02/10/2009, 11:01 PM

is your default set in ccs or in sql?
if set in sql i think it should work as you would expect - if set in ccs technically there is new data... i wonder if you could write some error checking? if no value enterred in field a, clear values in field (default) b?

_________________
if you found this post useful take the time to help someone else.... :)
View profile  Send private message
jacem

Posts: 87
Posted: 02/11/2009, 1:42 PM

Thanks for responding Damian.

I suppose that's the point: I really don't think that a default is 'technically' new data. The default is set in CCS. I can set the default in custom insert if the field is blank but I want to show the users what they are saving in a defaulted field before they hit submit.

In your suggestion are you talking about code in the event trigger 'row validate'?

Thanks for your interest...

Quote damian:
is your default set in ccs or in sql?
if set in sql i think it should work as you would expect - if set in ccs technically there is new data... i wonder if you could write some error checking? if no value enterred in field a, clear values in field (default) b?

View profile  Send private message
mentecky

Posts: 321
Posted: 02/11/2009, 2:14 PM

jacem,

Pick a column in the row that would be required and is not set to a default value. In it's On Validate add the following code:
 if ($Component->GetValue() == "")    
   {    
      $Container->InsertAllowed = false;    
   }    
   else    
   {    
      $Container->InsertAllowed = true;    
   }    
That should prevent the blank rows from being inserted.

Rick
_________________
http://www.ccselite.com
View profile  Send private message
damian

Posts: 838
Posted: 02/11/2009, 3:29 PM

but it would also throw an error message?
would it also stop the correctly changed records from being inserted?

i think a similar approach where you check for a field that would always be filled but not with a default value (I think that is probably what you are saying rick) and if it is blank also change the other fields in that row to blank....

what the actual syntax is to change those fields i dont know off top of head and havent time to test just now

you would use the initial part of rick's code to check and something similar to change the values of the other items - making sure it only changed the values in that row

$Container->$TextBox->SetValue("")

need to test make sure it is only changing the values for the current row too!

thats where i am thinking you need to go

and i agree with you that in terms of your human logic it shouldnt insert these rows, but that is because your human logic is already taking into account the fact that you didnt enter any data. the ccs grid may not know that because after it was loaded some (default) values were applied so it wants to submit them....
_________________
if you found this post useful take the time to help someone else.... :)
View profile  Send private message
jacem

Posts: 87
Posted: 02/11/2009, 3:48 PM

Well I think it can be simple computer logic as well: if the non-defaulted fields still have nothing in them and the defaulted fields still contain the same default then no change has occurred and no new record should be inserted. :-)

Thank you very much both of you for the code suggestions, I will try them and report back soon.

Quote damian:
and i agree with you that in terms of your human logic it shouldnt insert these rows, but that is because your human logic is already taking into account the fact that you didnt enter any data. the ccs grid may not know that because after it was loaded some (default) values were applied so it wants to submit them....
:-)
View profile  Send private message
jacem

Posts: 87
Posted: 02/11/2009, 6:19 PM

Providing a default for a field then using the InsertAllow=true or false approach as suggested doesn't work (in my case). Yes it does still throw the error message and yes it does stop the correctly changed records from being inserted.

My problem is getting CCS to use my field changes made during the BeforeBuildInsert event trigger code.

The if tests are working perfectly such as If ($Container->Note->GetValue()=='') { etc...I have check this by doing some text file tracing of where the code steps to).

but any change to the contents of the fields are ignored during insert. No error message - the changes are just not reflected in the database. I have tried the syntax:

$Container->FieldName->SetValue("Hello");

as well as referencing the grid specifically:

$Gridname->FieldName->SetValue("hello");

(replacing Gridname & fieldname with the actual name of the grid and name of the field).

I have checked this by reviewing the data on the database itself, not just relying on what ccs is displaying upon page refresh.

Thanks for your continued interest in this...


Quote damian:

but it would also throw an error message?
would it also stop the correctly changed records from being inserted?

View profile  Send private message
damian

Posts: 838
Posted: 02/11/2009, 7:40 PM

bounce this off support - i think the issue you might be having is limiting the actions of the checking and clearing to the specific row? is that correct?
support may be able to help you reference the current row correctly.
and post your solution back here :)

_________________
if you found this post useful take the time to help someone else.... :)
View profile  Send private message
jacem

Posts: 87
Posted: 02/11/2009, 7:47 PM

You maybe right on the specific row thing (although I have put the code into validaterow as a bit of a hail mary - didn't change things)

...have submitted it support now and will report back.

Quote damian:
bounce this off support - i think the issue you might be having is limiting the actions of the checking and clearing to the specific row? is that correct?
support may be able to help you reference the current row correctly.
and post your solution back here :)

View profile  Send private message
damian

Posts: 838
Posted: 02/11/2009, 8:17 PM

include this thread or its workings in your request...
_________________
if you found this post useful take the time to help someone else.... :)
View profile  Send private message
jacem

Posts: 87
Posted: 02/12/2009, 4:31 PM

RESOLUTION:

OK: for everyone who wanted to have defaults for certain controls (fields) in an editable grid without getting blank records added for rows that the user had not entered any (new) data for, here is the solution.

There are three little tricks (well they are tricks to me - probably straight forward for more experienced PHP/CCS people out there).

1. You can not have any 'custom insert' set up. You have to do your own code to look after any custom insert needs (ie: automatic timedate stamp on a record).

2. You must place the code for this replacement custom insert code in the BeforeBuildInsert (obviously but I was testing putting the code in ValidateRow triggers during this journey - which doesn't work)

3. You need to update your controls within the BeforeBuildInsert using the php referencing code: $Container->DataSource->YourControl->SetValue("yourdefaultvalue");

Steps:

A. So first step is to note what custom insert instructions you have set up for the editable grid in question then

B. remove those custom insert settings. Otherwise your control changes will be overwritten by the CCS routines that handle CustomInserts

C. In the Event Trigger BeforeBuildInsert you will put your logic to handle the defaults

My example if a certain control called 'notes' was empty then I didn't want to add that particular editable grid row. If it wasn't empty it needed to be added using the data entered by the user. However if the user didn't enter any data for my example field ProjectID then I wanted to default that project ID during the save to the text "ADMIN". The record also captured automatically the user who added this note using the session variable "UserID".

Thus the code in the BeforeBuildInsert is:

if ($Container->Note->GetValue()=='') {

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

} else {

//notes recorded, better record the user in the record and default the project if
//needed. is blank fill it in with the current userid

$Container->InsertAllowed = true;

//we need to replicate the actions of the custom insert here
//note who by
$Container->DataSource->ByWho->SetValue(CCGetSession("UserID"));

if ($Container->ProjectID->GetValue()=='') {
//projectid is empty use 'ADMIN'

$Container->DataSource->ProjectID->SetValue("ADMIN");
}
}

Thus if the project control is left empty it is filled up with the default. The record will belong to UserID automatically.

I hope this helps others (as others have helped me in the past).

Big thankyou to Helen from Support, damian & Richard (mentecky) for tips to get us to a resolution of the defaults in editable grids issue.


:-) :-)
View profile  Send private message
mentecky

Posts: 321
Posted: 02/12/2009, 5:28 PM

jacem,

Glad to help in some way!

Rick
_________________
http://www.ccselite.com
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.

Web Database

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.