Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

Dynamic form Label / form input type 02 Apr 2013 08:28 #7015

  • MorganL
  • MorganL's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
I will try to describe best I can and see if anyone can advise how best to do this in Cook.

I have a table called contact_types, and a table called contacts

In contact types, I have fields of name, and variable1, variable1_type (variable2 and 3 in same format). The type is an enumeration list of either string (0), or boolean (1)

In contacts I have name, contact_type (foreign key to contact_types), variable1 value, variable2 value and so on.

I want the label in contacts to have the name from contact_types and to determine if the type should be a boolean type or string type and give appropriate field type. I dont need this to be ajax as I am happy for and can easily code a message to popup on the screen when someone is creating a contact that says 'you must press save after selecting contact type'

Working example

Someone defines a contacttype of

name - IT Consultant
Variable_1_type = Boolean
Variable_1_string = 24 hour callout
Varianle_2_type = String
Variable_2_string = Operating systems supported


and when someone creates a new contact of type IT Consultant and clicks SAVE the fields for these variables (that are always known as var1value,var2value,var3value) that are

24 hour callout (YES / NO)
Operating system Supported = INPUT BOX

The information in these field is always saved as a string, I just need the label and form type to lookup from contact_type and render appropriately.

Any starting tips greatly appreciated
Morgan Leecy MCSE

Novell / Linux
PHP. MYSQL, Apache, node.js
Coldfusion, JQuery, HTML5
Joomla

Please Log in or Create an account to join the conversation.

Re: Dynamic form Label / form input type 02 Apr 2013 11:57 #7016

  • MorganL
  • MorganL's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
I have most of it done and working HOWEVER i have one stumbling block that I can work through manually by not using the form XML file.

I need to be able to make the system use either of the following depending on what the variable type is

<field name="variable_1_value"
label="XXX_FIELD_VARIABLE_1_VALUE"
alias="variable_1_value"
filter="STRING"
type="cktext"/>

<field name="variable_1_value"
label="com_xxx_FIELD_VARIABLE_1_VALUE"
alias="variable_1_value"
filter="BOOL"
type="ckcombo"
nullLabel="XXX_JSEARCH_SELECT">
<option value="0">XXX_FIELDS_BOOL_NO</option>
<option value="1">XXX_FIELDS_BOOL_YES</option>
</field>

I have tried using a different alias as a referal with no success, and of course changing the name means the variable is not passed. Is there a way of altering the XML so that two fields can have the same field name, but will be of different types depending on what is called?
Morgan Leecy MCSE

Novell / Linux
PHP. MYSQL, Apache, node.js
Coldfusion, JQuery, HTML5
Joomla

Please Log in or Create an account to join the conversation.

Re: Dynamic form Label / form input type 02 Apr 2013 12:38 #7017

  • MorganL
  • MorganL's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
OK I know this is a one man discussion =) however I have implemented a sticking plaster fix which I open up the floor for abject criticism and offers of betterment

Here goes

in the contact.xml file I did a hybrid select box like so
<field name="variable_1_value"
				label="XXXX_FIELD_VARIABLE_1_VALUE"
				alias="variable_1_value"
				filter="STRING"
				type="ckcombo"
				nullLabel="XXXX_JSEARCH_SELECT">
				<option value="0">XXXX_FIELDS_BOOL_NO</option>
				<option value="1">XXXX_FIELDS_BOOL_YES</option>
		</field>			

this generates a simple select list for when the type is boolean BUT will also allow strings due to the filter=STRING and not the usual filter="BOOL"

I then modified the contact.php MODEL by adding the following to the query
$this->addSelect('_contact_type_.var_1_desc AS `_contact_type_var_1_desc`');
				$this->addSelect('_contact_type_.var_2_desc AS `_contact_type_var_2_desc`');
				$this->addSelect('_contact_type_.var_3_desc AS `_contact_type_var_3_desc`');
				$this->addSelect('_contact_type_.var_1_type AS `_contact_type_var_1_type`');
				$this->addSelect('_contact_type_.var_2_type AS `_contact_type_var_2_type`');
				$this->addSelect('_contact_type_.var_3_type AS `_contact_type_var_3_type`');

I then altered the template file to
<dt><label id="jform_variable_1_value-lbl" for="jform_variable_1_value" class=""><?php echo $this->item->_contact_type_var_1_desc; ?></label></dt>
    <dd>
		<?php if ($this->item->_contact_type_var_1_type == 0)  { ?>
			<input type="text" id="jform_variable_1_value" name="jform[variable_1_value]" class="inputbox " value="<?php echo $this->item->variable_1_value; ?>" size="32">	
		<?php } else { ?>
		<?php 
			$field = $fieldSet['jform_variable_1_value'];
			echo $field->input; ?><?php }; ?>
	</dd>

so if the type is 0 (string) a manually coded input box is generated, if the type is 1 (yes or no select box) the standard field is generated,

It works, happy for now, most of it seems to follow the standard generated component. Ideally I would like to have two entries in the XML and just call it the typical way, but i cant see how this would be done
Morgan Leecy MCSE

Novell / Linux
PHP. MYSQL, Apache, node.js
Coldfusion, JQuery, HTML5
Joomla

Please Log in or Create an account to join the conversation.

Re: Dynamic form Label / form input type 02 Apr 2013 12:51 #7018

  • MorganL
  • MorganL's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
and the final version of the view now checks that the variable is actually required
<!-- Variable 2 -->
	<?php if ($this->item->_contact_type_var_2_desc)  { ?>
		<dt><label id="jform_variable_2_value-lbl" for="jform_variable_2_value" class=""><?php echo $this->item->_contact_type_var_2_desc; ?></label></dt>
		<dd>
			<?php if ($this->item->_contact_type_var_2_type == 0)  { ?>
				<input type="text" id="jform_variable_2_value" name="jform[variable_2_value]" class="inputbox " value="<?php echo $this->item->variable_2_value; ?>" size="32">	
			<?php } else { ?>
			<?php 
				$field = $fieldSet['jform_variable_2_value'];
				echo $field->input; ?><?php }; ?>
		</dd>
	<?php } ?>
<!-- Variable 2 end -->
Morgan Leecy MCSE

Novell / Linux
PHP. MYSQL, Apache, node.js
Coldfusion, JQuery, HTML5
Joomla

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Time to create page: 0.080 seconds

The j-cook project is one of the best of its kind and it is nice that we all try to contribute in little ways to make life easy for each other.

vlemos (Forum)  

Get Started