Welcome, Guest
Username: Password: Remember me

TOPIC: Javascript duplicates fields in form

Javascript duplicates fields in form 14 Mar 2012 20:44 #1605

  • etc
  • etc's Avatar
  • Offline
  • Premium Member
  • Posts: 132
  • Thank you received: 19
  • Karma: 7
I am filing a form with data. I would like to add another one or more set of fields in the same form and then
save it all in one step.

for example:

in my views/../tmpl/myfile.php

I put this script (adds input file field):
<script language="javascript">
fields = 0;
function addInput() {
if (fields != 3) {
 document.getElementById('entireform').innerHTML += "<input type='file' value='' name='fields[]' /><br />";
 fields += 1;
 } else {
   document.getElementById('entireform').innerHTML += "<br />Only 3 upload fields allowed.";
   document.form.add.disabled=true;
 }
}
</script>

.
.
.

this continues with native j-cook code
<table class="admintable">

		<tr>
			<td align="right" class="key">
				<label for="entry_date">
					<?php echo JText::_( "TRAINING_FIELD_ENTRY_DATE" ); ?> :
				</label>
			</td>
			<td>
				<?php echo JDom::_('html.form.input.calendar', array(
												'dataKey' => 'entry_date',
												'dataObject' => $this->xyz,
												'dateFormat' => "%Y-%m-%d",
												'required' => true,
												'validatorMsgRequired' => "VALIDATOR_ENTER_THE_DATE",
												'validatorHandler' => "datetime",
												'validatorMsgInfo' => "VALIDATOR_ENTER_OR_EDIT_THE_DATE"
												));

				?>
			</td>

The javascript script above is called by:
<input type="button" onclick="addInput()" name="add" value="Add another field" />

So the question is whether it is feasible in this way to duplicate the fields?

Need to replace:
<input type='file' value='' name='fields[]' /><br />

with
JDom::_('html.form.input.calendar'.....
Last Edit: 14 Mar 2012 20:45 by etc.
The administrator has disabled public write access.

Re: Javascript duplicates fields in form 16 Mar 2012 17:02 #1622

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
Hum...
Very good question.
Not thinked about for the moment.

Let's fill a JS var with the result of a JDom call as template to reproduce.
var inputTemplate = "<?php echo(JDom::_('html.form.input.calendar'.....)); ?>";

Then, search and replace what you want inside.


I am not sure about the JS calls that JDom produce in the output headers.

So....
To my opinion, don't use JDom for that. (the more easy, and make sense)

OR :
Extend the JDom framework for JS dynamic instances... :-)
Coding is now a piece of cake
The administrator has disabled public write access.
Time to create page: 0.076 seconds

Get Started