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

For starters it's just so easy to design an app in a way that I'm used to i.e. database first then views followed by customization. The fork system is pure brilliance from a developer standpoint as I can override things and still add and update my projects with minimal effort! Truly amazing to be able to build components in Joomla using incremental refinement without having to do everything by hand. Thanks for the great tool! I am so much more productive now than ever and I can't imagine building components any other way!!!!
Dave (Forum)

Get Started