i can't insert text into text area of JFactory::getEditor().
$("textarea").val('some text');
can't update text area in my dom.
If i use a default <textarea> it work fine.
<?xml version="1.0" encoding="UTF-8"?>
<form>
<fieldset addfieldpath="/administrator/components/com_categories/models/fields" >
<field
type="editor"
name="myEditorField"
id="myEditorField"
label="MY EDITOR FIELD LABEL"
description="MY EDITOR FIELD DESCRIPTION"
width= "99%"
rows="5"
editor="desired|alternative"
cols="200"
buttons="true"/>
<field name="articletext" type="editor" class="inputbox"
label="COM_CONTENT_FIELD_ARTICLETEXT_LABEL" description="COM_CONTENT_FIELD_ARTICLETEXT_DESC"
filter="JComponentHelper::filterText" buttons="true" />
</fieldset>
</form>
save above code in editor.xml and use following php code to display editor
<?php
$mypath= JPATH_COMPONENT.'/views/' .'createTask'. '/tmpl/editor.xml';
$form = JForm::getInstance('myform',$mypath );
echo $form->getInput('myEditorField');
?>
follwoing code will echo javascript to set editor content
$editor =JFactory::getEditor();
$setContent=$editor->setContent($name,'hello');
$js1 = 'function setEditorText (){return '.$setContent.'}';
$doc= JFactory::getDocument();
$doc->addScriptDeclaration($js1);
for details click here
.
.
.
.
Other way to get and set content in JOOMLA editor is use following js.
Wrap your editor in div having class .myPreviewEditor
to set content
$('.myPreviewEditor iframe').contents().find('body').html("i am in editor");
to get content
$editoContent=$('.myPreviewEditor iframe').contents().find('body').html();
but make sure that these statement execute after JOOMLA editor loads itself
Related
I have in my component in admin section my "config.xml", the config inputs are ok on the administration of Joomla.
I have for example a field with "my_custom_test" and I set a value, for example "test". I click on "save" button.
If I'm in a view and I want to get my value I'm writing that
$compo_params = JComponentHelper::getParams('com_xxxxx');
var_dump($compo_params).'<br />';
echo $compo_params->get('my_custom_test', 'EMPTY');
The result is that
object(Joomla\Registry\Registry)#19 (2) { ["data":protected]=> object(stdClass)#20 (1) { ["params"]=> object(stdClass)#57 (1) { ["my_custom_test"]=> string(4) "test" } } ["separator"]=> string(1) "." }
EMPTY
The result is "EMPTY" instead of "test".
Do you have any idea ?
Actually I have found the source of the problem, it is in the component config.xml file. If you have the parameters enclosed in a tag (which was the standard practice for Joomla in the past), then the parameters are stored inside an object called "params", eg
<?xml version="1.0" encoding="utf-8"?>
<config>
<fields name="params" label="Some label">
<fieldset name="basic" label="Basic Options" description="">
<field name="some_option" label="label" type="text" description="" />
</fieldset>
</fields>
</config>
To correct the problem, just leave out the tag:-
<?xml version="1.0" encoding="utf-8"?>
<config>
<fieldset name="basic" label="Basic Options" description="">
<field name="some_option" label="label" type="text" description="" />
</fieldset>
</config>
If you look at any of the core Joomla component config.xml files this is how they do it now.
Then the standard method of getting the component params works:-
$compo_params = JComponentHelper::getParams('com_xxxxx');
$my_custom_test = $compo_params->get('my_custom_test', '');
The solution is
echo $compo_params->get('params')->my_custom_test;
I would like to allow users to be able to enter multiple dates, and was hoping I could use the repeatable form field type (new as of Joomla 3.3).
I do get the modal popup with rows to add/remove items, however the calendar icon does not popup a calendar picker. I tried with just a text input and that seems to work ok.
The relevant part of my form definition:
<field
name="event_dates"
type="repeatable"
id="event_dates"
icon="calendar"
label="Event calendar dates"
select="Select dates"
>
<fields name="jmfields_event_dates">
<fieldset
name="event_dates_modal"
repeat="true"
hidden="true">
<field
name="event_date"
type="calendar"
format="%d-%m-%Y"
label="Date"
/>
</fieldset>
</fields>
</field>
I haven't tried to have a calendar field inside the Repeatable field, but Repeatable field is too buggy yet with a bunch of javascript issues/conflicts. Check in your browser error console for any such issues. I would suggest to wait till Repeatable Field becomes more stable.
I also wanted to do the same, and instead of the default calendar field I end-up using the jQuery date picker on a normal text field instead. You add the jQuery script on the page to target the input field and you have a little work around until the actual fix for the default calendar is out.
You need these files in your header:
JHtml::_('jquery.framework');
JHtml::_('jquery.ui');
$doc =& JFactory::getDocument();
// loaded from the code.jquery.com site
$doc->addStylesheet('http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css');
// I downloaded the datepicker only and placed it in this folder
$doc->addScript(JURI::root().'/media/jui/js/datepicker/jquery-ui.min.js');
The xml for the field:
<!-- Course_date Field. Type: Repeatable. (joomla) -->
<field
type="repeatable"
name="course_date"
label="Course Dates"
description="COM_LEARNINGMANAGER_EVENT_COURSE_DATE_DESCRIPTION"
id="course_date"
class="course_dates"
select="COM_LEARNINGMANAGER_EVENT_COURSE_DATE_SELECT"
icon="list"
maximum="50">
<fields name="course_date_fields" label="">
<fieldset hidden="true" name="course_date_modal" repeat="true">
<!-- Course Field. Type: Courses. (custom) -->
<field
type="courses"
name="course"
label="COM_LEARNINGMANAGER_EVENT_COURSE_LABEL"
class="list_class"
button="false"
/>
<!-- Date Field. Type: Text. (joomla) -->
<field
type="text"
name="date"
label="COM_LEARNINGMANAGER_EVENT_DATE_LABEL"
size="20"
maxlength="50"
description="COM_LEARNINGMANAGER_EVENT_DATE_DESCRIPTION"
class="text_area datepicker"
readonly="false"
disabled="false"
filter="STRING"
message="Error! Please add date here."
hint="COM_LEARNINGMANAGER_EVENT_DATE_HINT"
/>
</fieldset>
</fields>
</field>
Here is the script you need to add to the default.php or edit.php file:
<script type="text/javascript">
// means your repteable field can only take 50 rows
<?php $fieldNrs = range(1,50,1); ?>
jQuery('input.form-field-repeatable').on('row-add', function (e) {
<?php foreach($fieldNrs as $nr): ?>
jQuery('#jform_course_date_fields_date-<?php echo $nr ?>').datepicker(
{
minDate: -1,
prevText: '',
nextText: '',
maxDate: '+3M',
firstDay: 1,
dateFormat: 'yy-mm-dd',
onSelect: function(dateText, inst) {
jQuery('#jform_course_date_fields_date-<?php echo $nr ?>').val(dateText);
}
});
<? endforeach; ?>
});
</script>
Enjoy!
You can try with this ("Multiplier module"). I used different approach to get same result like with Joomla repeatable form field type, and also with that avoid "pop-ups inside popup". Still in development phase, but maybe you can try with that concept. Regards.
What I did to solve similar problem?
I had a similar problem with default Joomla repeatable form field type, especially with "pop-up" form fields type (eg. Joomla "date"). Because of that I created some kind of module pattern (mod_multiplier) where I used different approach -> I wouldn't repeat form of fields (section), I want to use same section for multiple insertion.
Module mod_multiplier
Inside module xml file are 3 reserved fields "wrapper", "repeater", and "content".
Inside "wrapper" is the place for "repeatable" fields:
<fieldset name="basic" addfieldpath="/modules/mod_multiplier/models/fields">
<!-- Wrapper is container for repeatable fields-->
<fields name="wrapper">
<!--This is the place where you insert your fields-->
</fields>
<field name="repeater" label="" type="repeater" />
<field name="content" hidden="true" label="Content" type="hidden" />
</fieldset>
All content would be stored inside "content" field in JSON format. Every time when we press form "Add" button we will add one row of data to "content" field. After all, inside "content" we will have rows of data.
How that look inside tmpl/default.php file and how to get fields values?
Hierarchical data structure has 3 levels: rows, row and field.
all data => $rows
one row of data => $row
one field => $row->field_name
Practical example from mod_multiplier:
Inside "wrapper" are fields "country", and "city" and we call them by name (inside tmpl/default.php) like this:
<ul>
<?php foreach ($rows as $row):?>
<li>
<?php echo $row->country;?>:<?php echo $row->city;?>
</li>
<?php endforeach; ?>
</ul>
I have a small Question about setting Tab Names Dynamically.
I am Thinking to create an options.js and I want my tab names to gather data from options.js
<Alloy>
<TabGroup>
<Tab title="Tab 1" icon="KS_nav_ui.png">
<Window class="tab1" title="Tab 1">
<Label>I am Window 1</Label>
<Button class="exampleBut">Button </Button>
</Window>
</Tab>
</TabGroup>
</Alloy>
I would like to set Tab 1 Title from another JS file.
How to solve it ?
Regards
You have to identify the tab by a unique id
<Tab title="Tab 1" id='tab1' icon="KS_nav_ui.png">
in the same js file for exemple index.js (the tab is defined in index.xml) you can use :
$.tab1.title="my title"
if you would set title from another js file you can use application events:
in index file you define an application event listener :
Ti.App.addEventListener("app:changeTabTitlle",function(e){
$.tab1.title=e.title;
});
and from the other js file you have to send the tab title using fireEvent:
Ti.App.fireEvent("app:changeTabTitlle",{title:"My tab title"});
I want to set max length from default.php.
Here is my XML format,
<fieldset name="sender_details">
<field name="sendername"
type="text"
label="SENDERV_SENDER"
description="SENDERV_SENDER_DESC"
default=""
required="true" />
</fieldset>
Here is the coding for default.php.
foreach ($this->form->getFieldset('sender_details') as $field) :
echo $field->label;
echo $field->input;
}
I had a variable $length=5.The text box should allow only 5 characters.The length is coming from the configuration. I need to do in default.php
kindly Help Me.
To specify max length in Joomla Text Field Like This
<fieldset name="sender_details">
<field name="sendername"
type="text"
label="SENDERV_SENDER"
description="SENDERV_SENDER_DESC"
default=""
maxlength="5"
required="true" />
</fieldset>
if you want your custom attribute then you can create joomla new field type or you can modify joomla form fields
libraries/joomla/form/fields/text.php
libraries/joomla/form/fields/textarea.php
libraries/joomla/form/fields/.......
any problem implementing please reply
The problem with editing core-files (libraries/joomla/form/fields/text.php, libraries/joomla/form/fields/textarea.php, libraries/joomla/form/fields/...) is, that with the next joomla-update these changes could be overwriten again.
Until joomla does noch correct this bug, is there any possibility to set a custom html-attribute to a jformfield before it renders with "print $field->input;" ?
edit: There already exists a bug-entry for that: http://issues.joomla.org/tracker/joomla-cms/3510?lang=de-DE
You can set in edit layout like this :
<?php echo $this->form->getInput('fieldname','maxLength',4); ?>
And then your html code is :
<input type="text" name="jform[fieldname]" id="jform_fieldname" maxlength="4">
I have a Joomla 1.5 component that uses a call to the editor class to display JCE for Joomla instead of a textbox. This code is part of a 4-step form where each step is loading using ajax. The last step contains a message field where users can write free text and I am calling this using the following code:
$editor =& JFactory::getEditor();
echo $editor->display('description', $description, '100%', '150', '40', '30');
When this step is displayed, it shows only a simple textbox without the buttons to format the text etc. I understand this must be an issue with the javascript, but I am having a hard time finding how I can trigger the proper code for the textbox to be formatted properly.
This is how the field looks:
And here is the HTML generated from Firebug:
<!-- Start Editor --><label aria-visible="false" style="display:none;" for="description">description_textarea</label><textarea wrap="off" class="wfEditor source" style="width:100%;height:150px;" rows="30" cols="40" name="description" id="description"></textarea><input type="hidden" value="1" name="wf3fadc9c48cabc28750287fe69c3d08c4" id="wf_description_token">
<div id="editor-xtd-buttons">
<div class="button2-left"><div class="image"><a rel="{handler: 'iframe', size: {x: 570, y: 400}}" onclick="IeCursorFix(); return false;" href="http://localhost/ugparl/site/index.php?option=com_media&view=images&tmpl=component&e_name=description" title="Image" class="modal-button">Image</a></div></div>
<div class="button2-left"><div class="pagebreak"><a rel="{handler: 'iframe', size: {x: 400, y: 85}}" onclick="IeCursorFix(); return false;" href="http://localhost/ugparl/site/index.php?option=com_content&task=ins_pagebreak&tmpl=component&e_name=description" title="Pagebreak" class="modal-button">Pagebreak</a></div></div>
<div class="button2-left"><div class="readmore"><a rel="" onclick="insertReadmore('description');return false;" href="http://localhost/ugparl/site/#" title="Read more">Read more</a></div></div>
</div>
<!-- End Editor -->
This is not so much a solution but a workaround. Due to cleaning the headers before displaying the page, the code generated by JCE is lost. By adding the following code to the page called by ajax, I am able to trigger the JCE initializer and display the editor correctly.
$document =& JFactory::getDocument();
echo "<script type='text/javascript'>
function loadJCE() {";
echo $document->_script["text/javascript"];
echo "}
</script>";
Then I just called loadJCE from the load complete function.
Again, this is not the best way to do it but it did the trick for me.