Add Remove Input Fields Dynamically

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
yasin.1987
User
Posts: 4

Add Remove Input Fields Dynamically

Post by yasin.1987 »

Hi .

For example, I have a table of the database:

{
id
subjectofthetreaty
workitems [] ~ unit[] ~ priceperunit[] ~ amount[]
generalconditions[]
privateconditions[]
}

And I want to extract the following fields from the table above:

Subject of the treaty:
<input type="text" name="Subjectofthetreaty">

Work items :

  1. <input type="text" name="workitems[]"> ~ <input type="text" name="unit[]"> ~ <input type="text" name="Priceperunit[]"> ~ <input type="text" name="Amount[]">
  2. <input type="text" name="workitems[]"> ~ <input type="text" name="unit[]"> ~ <input type="text" name="Priceperunit[]"> ~ <input type="text" name="Amount[]"> × (Remove Filed)
  3. <input type="text" name="workitems[]"> ~ <input type="text" name="unit[]"> ~ <input type="text" name="Priceperunit[]"> ~ <input type="text" name="Amount[]"> × (Remove Filed)
  4. (Add More Field)

general conditions :

  1. <input type="text" name="generalconditions[]">
  2. <input type="text" name="generalconditions[]"> × (Remove Filed)
  3. <input type="text" name="generalconditions[]"> × (Remove Filed)
  4. (Add More Field)

private conditions :

  1. <input type="text" name="privateconditions[]">
  2. <input type="text" name="privateconditions[]"> × (Remove Filed)
  3. <input type="text" name="privateconditions[]"> × (Remove Filed)
  4. (Add More Field)

Is PHPMAKER now possible?


kirondedshem
User
Posts: 642

Post by kirondedshem »

here are ways to remove a field from an add/edit/list/view form:
-untick it from the respective form in field settings
-RECOMMENDED:Set the Visible property at run_time(I prefer this approach as it works anywhere and you can add as many conditions as you want beore you call it)
page_load()
{
//check condition
$this->field_name->Visible =FALSE;
}

If you want to first depend on some values on the forms then do it in page_render/page_data_rendering.

I still dont undertand some of what you explained.
are workitems,generalconditions,privateconditions detail tables to subjectoftreaty table?
is there a special condition under which you would like to remove the fields.
from which form do you want to remove the filed, add,edit,list,view etc?


yasin.1987
User
Posts: 4

Post by yasin.1987 »

Thank you for your answer.

I have a table:

CREATE TABLE conditions (
id bigint(20) NOT NULL,
subjectofthetreaty text,
workitems text,
unit text,
priceperunit text,
amount text,
generalconditions longtext,
privateconditions longtext) ENGINE=MyISAM DEFAULT CHARSET=latin1;

Without any connection to another table ....


kirondedshem
User
Posts: 642

Post by kirondedshem »

Use $this->field_name->Visible =FALSE; to hide a field from any form dynamically.

Otherwise if you still dont get it then:
-so which filed do you want to hide
-when do you want to hide it and under what conditions.
-on which form do you want to hide it


yasin.1987
User
Posts: 4

Post by yasin.1987 »

I do not want to hide the field

I want to use some of the fields in the form of "TYPE =" TEXT as an array.

html :

<table>
<tbody>
<tr>
<td>Subject of the treaty: <input name="Subjectofthetreaty" type="text" /></td>
</tr>
<tr>
<td>Work items :</td>
</tr>
<tr>
<td>1. <input name="workitems[]" type="text" /> ~ <input name="unit[]" type="text" /> ~ <input name="Priceperunit[]" type="text" /></td>
</tr>
<tr>
<td>2. <input name="workitems[]" type="text" /> ~ <input name="unit[]" type="text" /> ~ <input name="Priceperunit[]" type="text" /> &times; (Remove Filed)</td>
</tr>
<tr>
<td>3. <input name="workitems[]" type="text" /> ~ <input name="unit[]" type="text" /> ~ <input name="Priceperunit[]" type="text" /> &times; (Remove Filed)</td>
</tr>
<tr>
<td>+ (Add More Field)</td>
</tr>
<tr>
<td>general conditions :</td>
</tr>
<tr>
<td>1. <input name="generalconditions[]" type="text" /></td>
</tr>
<tr>
<td>2. <input name="generalconditions[]" type="text" /> &times; (Remove Filed)</td>
</tr>
<tr>
<td>3. <input name="generalconditions[]" type="text" /> &times; (Remove Filed)</td>
</tr>
<tr>
<td>+ (Add More Field)</td>
</tr>
<tr>
<td>private conditions :</td>
</tr>
<tr>
<td>1. <input name="privateconditions[]" type="text" /></td>
</tr>
<tr>
<td>2. <input name="privateconditions[]" type="text" /> &times; (Remove Filed)</td>
</tr>
<tr>
<td>3. <input name="privateconditions[]" type="text" /> &times; (Remove Filed)</td>
</tr>
<tr>
<td>+ (Add More Field)</td>
</tr>
</tbody>
</table>


kirondedshem
User
Posts: 642

Post by kirondedshem »

I want to use some of the fields in the form of "TYPE =" TEXT as an array.
#########what you are asking for##########
If you mean the field set as text are supposed to help you capture an array of items,
eg in workitems you want to store item_1,item_2,item_3, any maybe in workitems you want to store item_1,item_2,item_3
Then simply set the text fields to use a checkbox controll, which either has a defined list of items to pick from or uses lookup table to pick the list of items to pick from.
You can even set use modal dialog suc that a user can serac for an option to tick if they are many checkboxes
#########what you are asking for##########

#########WHAT I THINK YOU REALLY NEED TO DO##########
NOTE:In your replies I feel you might be approaching it wrong eg
-You dont mention anything about your original question(Add Remove Input Fields Dynamically)

  • You want to store priceperunit and unit as text yet they should be number formats

Basic on your Inititla approach If some sort of relation exists between the different array values selected by user in each input box
for example if a user sets
workitems = rice,bananas
unit = kgs, pieces
priceperunit = 3000,4000

And You want this to mean or would like later on to present it as
-rice costs 3000 per kg
-babansa cost 4000 per piece
Then this kind or relationship will be hard to formulate if they are all entered as arrays in multiple fields all in one table.Then you might want to create separate tables for them

If you want it to appear like you have drawn it on the form where one Subject of the treaty can have multiple collections of (workitesm and price per unit), multiple collections of general conditions and multiple collections of private conditions.
With an option to add more collections to any of those. as welll as remove a collection from them

Then your current table structure can not bring out that relationship. You need to design table structures that allow for the dynamic setup that you want to achive, for as long as an entity can appear multiple times for another entity then it deserves its own table.
Then you need it setup like one below:
CREATE TABLE subjectofthetreaty (
id bigint(20) PRIMARY KEY AUTO_INCREMENT,
name varchar(50)
)
ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE workitems (
id bigint(20) PRIMARY KEY AUTO_INCREMENT,
subjectofthetreaty_id bigint(20),
name varchar(50),
unit float,
priceperunit float,
FOREIGN KEY (subjectofthetreaty_id) REFERENCES subjectofthetreaty(id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE general_conditions (
id bigint(20) PRIMARY KEY AUTO_INCREMENT,
subjectofthetreaty_id bigint(20),
name varchar(50),
FOREIGN KEY (subjectofthetreaty_id) REFERENCES subjectofthetreaty(id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE private_conditions (
id bigint(20) PRIMARY KEY AUTO_INCREMENT,
subjectofthetreaty_id bigint(20),
name varchar(50),
FOREIGN KEY (subjectofthetreaty_id) REFERENCES subjectofthetreaty(id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

NOTICE how all the other netities reference the main one.
Now If you connect them to phpmaker and setup master/detail relationship approriately (read about it in help menu)
enable master/detail add and edit, you should have a form that looks exactly like you want.

#########WHAT I THINK YOU REALLY NEED TO DO##########


yasin.1987
User
Posts: 4

Post by yasin.1987 »

Thank you so much for your guide.


Post Reply