paulmason411
Posts: 127
|
| Posted: 08/21/2008, 10:29 PM |
|
Hi Guys,
I have an editable grid with 4 checkboxes, I need to make sure that the user has ticked at least one of these boxes.
My attempt:
- I created a hidden input at the bottom of the form called hdn_validate
- I then used this custom code for the checkboxes
global $hdn_validate;
if($Component->GetValue()){
$Container->hdn_validate->SetValue("1");
}
and added this code to the hidden field under the On Validate section:
if (!$Component->GetValue()) {
$Component->Errors->addError("<p>Please select at least one checkout method to continue.<p/>");
}
Any suggestions would be great
_________________
http://paulmason.name - Web Development Blog
|
 |
 |
wkempees
Posts: 1679
|
| Posted: 08/22/2008, 3:35 AM |
|
Quote :
I have an editable grid with 4 checkboxes, I need to make sure that the user has ticked at least one of these boxes.
This means you have 4 checkboxes per row?
And you want to check that at least one checkbox per row is ticked?
for every row that is updated or inserted, right?
(at least one means it can be more than one)
How many rows in total on editablegrid, and how many insert rows?
Walter
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)
if you liked this info PAYPAL me: http://donate.consultair.eu
|
 |
 |
paulmason411
Posts: 127
|
| Posted: 08/26/2008, 3:40 AM |
|
Sorry I was a bit vague in my first post. So... there are 4 checkboxes in total, 1 on each row and the only operation is to update. Let me know if this is still confusing and I will elaborate. Thanks in advance.
_________________
http://paulmason.name - Web Development Blog
|
 |
 |
wkempees
Posts: 1679
|
| Posted: 08/26/2008, 6:35 AM |
|
Paul,
Based on Example database Internet, an editable grid on store_products.
The EditableGrid is set to max 4 rows, update only.
The fields on the grid are all display but for 'is_recommended' a checkbox.
All else is standard generated.
Grid's Event-> Before Submit, Add Custom Code
//store_products_BeforeSubmit @2-493C9997
function store_products_BeforeSubmit(& $sender)
{
$store_products_BeforeSubmit = true;
$Component = & $sender;
$Container = & CCGetParentContainer($sender);
global $store_products; //Compatibility
//End store_products_BeforeSubmit
//Custom Code @17-2A29BDB7
// -------------------------
// Write your own code here.
// -------------------------
global $CCSLocales;
$Counted =0;
for ($j = 1; $j <= $Component->PageSize + $Component->EmptyRows; $j++)
if (strlen(CCGetParam("is_recommended_" . $j, ""))==1 ) //checked
$Counted+=1;
if ($Counted < 1) {
$Container->is_recommended->Errors->addError("At least one checked");
}
//End Custom Code
//Close store_products_BeforeSubmit @2-9026B68B
return $store_products_BeforeSubmit;
}
//End Close store_products_BeforeSubmit
Is what the final result looks like.
In your editable grid you can use the exact same code, just replace 'is_recommended' with the field name of your checkbox field.
Basically what 's done here is that when Submit is pressed, we loop through the checkboxes and see if the have a value as a checkbox can only have 1:0 True:False, the existence of the variable says it is checked.
We add 1 to $Counted variable for every checked value.
Finaly standard errorporcedure for $Counted being at least 1.
This should do it. http://www.consultair.eu/downloads/mason_2608.gif
(Please alter (all your resolved) topic title's to [Resolved] .... when done)
Walter
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)
if you liked this info PAYPAL me: http://donate.consultair.eu
|
 |
 |
paulmason411
Posts: 127
|
| Posted: 08/26/2008, 6:41 PM |
|
Thanks Walter, you are a genius!
p.s. What software did you use to create that gif?
_________________
http://paulmason.name - Web Development Blog
|
 |
 |
wkempees
Posts: 1679
|
| Posted: 08/26/2008, 6:49 PM |
|
DemoCharge 2005, of course!
I am an addict............
Glad you made it.
'till next we meet.
Walter
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)
if you liked this info PAYPAL me: http://donate.consultair.eu
|
 |
 |
|