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.097 seconds

Amazing Tool !
And only tool I know that allows complete Scaffolding in terms of component creation. It really saves loads of time (actually much more than that). Simple architecture enables quick and painless changes at any time. Code is clean and consintent. It's just... what's the word... neat! :) Great work! You should definetely try this one!

pi_wo (JED)
         

Get Started