PC SOFT

GRUPOS DE DISCUSSÃO PROFISSIONAL
WINDEVWEBDEV e WINDEV Mobile

Inicio → WEBDEV 2024 → CheckBoxes
CheckBoxes
Iniciado por Carlos, jan., 30 2023 12:39 PM - 1 resposta
Membro registado
37 mensagems
Publicado em janeiro, 30 2023 - 12:39 PM
Hello and thank you so much for the help in advanced.

I have been programing with WebDev now for a little while and this is the first time working with CheckBoxes (not Option Radios)

I have my website attached to an MS SQL Server 17.1
In my Table I have a Field named "CONDITION (Varchar(MAX)) supposed to be an Array Field
In my Page I have several data fields and within those fields a have checkbox named "CBOX_CONDITIONS with 5 options for the user to select,
This Checkbox is linked to the Field "CONDITIONS" in my MS SQL Table

The User can check more than one box in my CBOX_CONDITIONS then click on the Save button

The Problem
When the User clicks on the Save nothing gets saved
My Code on the Save Button

PagetoFile()
IF Hmodify(CUSTOMERS) Then
Info("data was Saved")
ELSE
Info("There was an Error")
END

My Data gets save from all the fields in my Page, except the values checked on the CheckBox Field with multiple boxes

In the help manual it talks that if the checkbox has multiple items it must be bind to an Array Field (My field CONDITIONS is set to an Array field in my database (MAX)

Question
1. What is it that I am doing wrong?

Thank you so much for the help.

Best regards,

Carlos

--
Best regards,

Carlos
Publicado em fevereiro, 02 2023 - 6:05 PM
Hello,

Since no one tried to help me or at least give me a hint on how to save and retrieve the values in a CheckBox with multiple selected items, I decided to break my head with a hammer until figuring out on how to solve this issue. There is no examples out there nether from the tutorials in any PCSoft products or from any developer. So I decided to post what I did which I know that my solution is not the best solution but it works.

I hope that these steps could help others specially those which are starting with WinDev Web or Mobile

Please correct any of the below steps if you have to

Here are the steps

My Database is an MS SQL Database.
My Table Name in my Database is: CONDITIONS.
My Field name inside the CONDITIONS Table is: CONDITION Varchar(MAX) //* For an Array Field.
A Table on my Page named TABLE_CONDITIONS.
A Button on my Page named Add Condition //Add a new Condition
A button on my Page named Edit Conditions. //Edit the Condition
A Popup on my page will hold Fields linked to my CONDITIONS Database Table and the CheckBox with multiple Items but linked to an Array Variable named varArrayMyConditions (see below)
A Save button in my Popup to save my fields and save the items we have selected on my CheckBox control.



1. On my Page Global Declarations section, I declared two Variables
//One Array and one String
1. varArrayMyConditions is array of 7 strings //The CheckBox has 7 options. The user can select multiple

2. varMyConditions is string

2. On my Add New Conditions Click (AJAX Enabled)
Hreset(CONDITIONS)//Reset My Database Table CONDITIONS and prepares it for a new record
FileToPage()

PopupDisplay(POPUP_CONDITIONS,popupCenter)//Display the Popup with the Conditions fields
and my CheckBox CBOX_CONDITIONS



3. On my page popup I selected the CheckBox named CBOX_CONDITIONS and linked to the newly created Array Variable “varArrayMyConditions”
//**** When clicking on the Link Tab, scroll all the way down and click on Variable, you will see
// the newly created array variable there. ****

3. On the Save Button located on my Popup select and enter the following code on the click event (AJAX Enable)

IF CONDITIONS..NewRecord = True THEN //If is a new record
PageToFile()

StringToArray(varMyConditions, varArrayMyConditions)

CONDITIONS.CONDITION = varMyConditions //Pass the values to the array field (CONDITION)
//located in the Table CONDITIONS


Hadd(CONDITIONS) //Then add the new Condition
TableDisplay(TABLE_MY_CONDITIONS) //Display the table to see the newly entered condition

ELSE //If the record is been edited when we click on the Edit Condition Button
PageToFile()

CONDITIONS.CONDITION = varMyConditions //The value of this variable is passed when
// we select the record on the TABLE_CONDITIONS

HModify(K9_DETECTIONS_MONTHLY_TRAINING)
//Re-Display the record and land the cursor on the edited record
TableDisplay(TABLE_CONDITIONS,gsSelected_Table_Record)
END



//How to retrieve the Values saved on the database so that they will display in our CheckBox?

1. On the table TABLE_CONDITIONS → Row selection code Section (AJAX Enabled) placed the following code”

//My TABLE_CONDITIONS is Linked to the CONDITIONS Table from my database
//A Column named COL_CONDITIONS is linked to the CONDITION Field from my Database Table

StringToArray(TABLE_CONDITIONS.COL_CONDITIONS, varArrayMyConditions)// This will pass the values from the Database Table CONDITION field to the array varArrayMyConditions

2. I created a button on my Page named "Edit Condition", we can select the Double Click event in the TABLE_CONDITIONS to point to this Button.

Code:
gsSelected_Table_Record = TableSelect(TABLE_CONDITIONS) //Gets the Table selected Record index

HreadSeekFirst(CONDITIONS,RECORD_ID,varRecord_Id) //Finds my record in the CONDITIONS //table
FileToPage()
PopupDisplay(POPUP_CONDITIONS,popupCenter)

//The multiple values are stored in the Database CONDITIONS table CONDITION field should now display in the CheckBox Control


I hope the above helps others

Conclusion: For me, this has been the most stressful learning curve I have experienced using WinDev, WebDev, however for me still my number one development tool in the Market.