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

TOPIC:

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

  • etc
  • etc's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
  • Posts: 132
  • Thank you received: 19
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'.....

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

Last edit: by etc.

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

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
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

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

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

Although I found this tool some time ago I just started learning experimenting and building this first component on Monday and now on Thursday afternoon it's already online. Although I already had a working version done with another tool this is much easier to build and at the end you have the freedom to own your own component. Once you know how to use Cook you will boost your productivity as the learning curve is really moderate compared to many other tools.
Giori (Forum)

Get Started