Prefill form-field

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
SPQRInc
Joomla! Intern
Joomla! Intern
Posts: 60
Joined: Sun Jan 05, 2014 1:00 pm

Prefill form-field

Post by SPQRInc » Wed Jul 23, 2014 3:07 pm

Hi,

I am working on a little mail-part of my component. In my edit-view there's an editor, which is used to format the email.

Well, I would like to add a list-field with different possible signatures. If I click on a signature, this signature should be filled into the editor.

Is that possible?

User avatar
NathanHawks
Joomla! Ace
Joomla! Ace
Posts: 1900
Joined: Wed Oct 02, 2013 6:17 pm
Location: Washington state, U.S.
Contact:

Re: Prefill form-field

Post by NathanHawks » Wed Jul 23, 2014 8:16 pm

Yes, via Javascript. E.g. if your dropdown has id="signature" and your textarea has id="message" you'd do something akin to:

msg = document.getElementById('message');
sig = document.getElementById('signature');
sigTxt = sig.options[sig.selectedIndex].value;
msgTxt = msg.value;
newMsg = msgTxt + "\n--\n" + sigTxt;
msg.value = newMsg;

You'd put that into a function to be called via the select's onChange.
Save time - hire me for your Joomla to-do list! http://nathanhawks.us/joomla

SPQRInc
Joomla! Intern
Joomla! Intern
Posts: 60
Joined: Sun Jan 05, 2014 1:00 pm

Re: Prefill form-field

Post by SPQRInc » Thu Jul 24, 2014 8:44 am

Hi nathan...

Thank you very much...

Well, I created a list like this:

Code: Select all

		<field
			name="signature" 
			type="list"
			label="" 
			description=""
			class="inputbox small" 
			size="1" 
			default="1"
			onchange="test();" >	
			<option value="test">Test</option>
			<option value="test2">Test2</option>
		</field>		
In my layout (edit.php) I added the following code:

Code: Select all

<SCRIPT LANGUAGE="JavaScript">
<!-- Beginning of JavaScript -

function test (textstring) {
msg = document.getElementById('message');
sig = document.getElementById('signature');
sigTxt = sig.options[sig.selectedIndex].value;
msgTxt = msg.value;
newMsg = msgTxt + "\n--\n" + sigTxt;
msg.value = newMsg;

alert (textstring) 

}

// - End of JavaScript - -->
</SCRIPT>
<form 	action="<?php echo JRoute::_('index.php?option=com_bestia&layout=edit&id='.(int) $this->item->id); ?>" 
		method="post"
		name="adminForm" 
		id="adminForm" 
		class="form-validate">

		<?php echo JLayoutHelper::render('joomla.edit.title_alias', $this); ?>


...

If change the list, I'm getting this error in the error console:
[Error] TypeError: 'null' is not an object (evaluating 'sig.options')
test (index.php, line 221)
onchange (index.php, line 307)
trigger (jquery.min.js, line 3)
trigger (jquery-migrate.min.js, line 2)
(anonyme Funktion) (jquery.min.js, line 3)
each (jquery.min.js, line 2)
each (jquery.min.js, line 2)
trigger (jquery.min.js, line 3)
result_select (chosen.jquery.min.js, line 1)
search_results_mouseup (chosen.jquery.min.js, line 1)
(anonyme Funktion) (chosen.jquery.min.js, line 1)
dispatch (jquery.min.js, line 3)
handle (jquery.min.js, line 3)

I'm not really a JS-guru... Maybe you can help me to find the error?

User avatar
NathanHawks
Joomla! Ace
Joomla! Ace
Posts: 1900
Joined: Wed Oct 02, 2013 6:17 pm
Location: Washington state, U.S.
Contact:

Re: Prefill form-field

Post by NathanHawks » Thu Jul 24, 2014 11:59 pm

I apologize, I have my own projects to take breaks from :)
Save time - hire me for your Joomla to-do list! http://nathanhawks.us/joomla

SPQRInc
Joomla! Intern
Joomla! Intern
Posts: 60
Joined: Sun Jan 05, 2014 1:00 pm

Re: Prefill form-field

Post by SPQRInc » Mon Jul 28, 2014 11:03 am

No problem...

If you find some time you maybe could help me out :)


Locked

Return to “Joomla! 3.x Coding”