Add tabs and fields to custom joomla component - php

How can i add more tabs and fields to a joomla component in backend,
-Tried editing the view xml file adding more fieldsets, no success
-Tried editing the edit file in view admin component, no success,
In other words i want to achieve this, just like the image
Any help?

You have to set it to the view template admin\views\*view_name\tmpl\*template_name.php.
The structure that you have to use is:
<?php echo JHtml::_('bootstrap.startTabSet', 'myTab', array('active' => 'general')); ?>
<?php echo JHtml::_('bootstrap.addTab', 'myTab', 'general', JText::_('COM_COMPONENT_NAME_TAB_1_NAME', true)); ?>
...
<?php echo JHtml::_('bootstrap.endTab'); ?>
<?php echo JHtml::_('bootstrap.addTab', 'myTab', 'advanced', JText::_('COM_COMPONENT_NAME_TAB_2_NAME', true)); ?>
...
<?php echo JHtml::_('bootstrap.endTab'); ?>
<?php echo JHtml::_('bootstrap.endTabSet'); ?>
You could also check core components to get more examples.
As for the contents of each tab, you could restrict the loop to get the fields of one fieldset only using:
<?php foreach ($this->form->getFieldset("general") as $field): ?>
<div class="control-group">
<div class="control-label"><?php echo $field->label; ?></div>
<div class="controls"><?php echo $field->input; ?></div>
</div>
<?php endforeach; ?>

Related

Joomla Error Message File Directory

I was trying to learn how to create a joomla template. I successfully override some modules and components on my template however I can't override the error message especially on form validation.
I would like to know where the files are located and is it possible to override? My purpose is to add some bootsrap classes and add more tags on it.
The actual generated system message is in /layouts/joomla/system/message.php
<div id="system-message-container">
<?php if (is_array($msgList) && !empty($msgList)) : ?>
<div id="system-message">
<?php foreach ($msgList as $type => $msgs) : ?>
<div class="alert alert-<?php echo $type; ?>">
<?php // This requires JS so we should add it trough JS. Progressive enhancement and stuff. ?>
<a class="close" data-dismiss="alert">×</a>
<?php if (!empty($msgs)) : ?>
<h4 class="alert-heading">
<?php echo JText::_($type); ?>
</h4>
<div>
<?php foreach ($msgs as $msg) : ?>
<div class="alert-message">
<?php echo $msg; ?>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
You can fix template CSS at /template/(your_template)/css/template.css
Or you can make new CSS with /template/(your_template)/css/my.css
and include it in the /template/(your_template)/index.php:
$doc->addStyleSheetVersion($this->baseurl . '/templates/' . $this->template . '/css/my.css');
If you need to temporary override CSS class from your CSS you can use " !important" about the overrided attribe in the CSS file.

Can Active Record running with HTML tag ? [YII]

I have a form like this as yii active record :
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'arsip-perihal-form',
// Please note: When you enable ajax validation, make sure the corresponding
// controller action is handling ajax validation correctly.
// There is a call to performAjaxValidation() commented in generated controller code.
// See class documentation of CActiveForm for details on this.
'enableAjaxValidation'=>false,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'nama_arsip'); ?>
<?php echo $form->textField($model,'nama_arsip',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'nama_arsip'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'kode_primary'); ?>
<?php echo $form->textField($model,'kode_primary',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'kode_primary'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'Keterangan'); ?>
<?php echo $form->textField($model,'Keterangan'); ?>
<?php echo $form->error($model,'Keterangan'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
Can I use a HTML tag, An example textbox
First name: <input type="text" name="fname"><br>
if it can, how to use it? how to set default from $model like the form above?
Thank You,
When you use $form->textField, CActiveForm generates a textbox with ModelName[attributeName] name. So you can provide name for your textbox with this structure.
<input type="text" name="ModelName[fname]">
Note, "ModelName" is your model class, for example, "User".

Geting multiple Records in update in Yii

I am developing this website that requires me to combine two models in one view where they have one to many relationship between them. The models name is Home and Image meaning Home has many Images but Image only has one Home.
I have manged to combine The view together but the problem that i encountering is to get all of the images. For example i have 6 images i want to display them or if i have 5 images i want to display them.
Home Controller UpdateMethod
public function actionUpdate($id)
{
$home=$this->loadModel($id);
$image=Image::model()->findByAttributes(array('homeId'=>$home->id));
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Home'],$_POST['Image'])){
$home->attributes=$_POST['Home'];
$image->attributes=$_POST['Image'];
$valid=$home->validate();
$valid=$image->validate() && $valid;
if($valid){
if($home->save()){
$image->save();
}
}
}
$this->render('update',array(
'home'=>$home,
'image'=>$image,
));
}
My _form.php to join them together
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'home-form',
// Please note: When you enable ajax validation, make sure the corresponding
// controller action is handling ajax validation correctly.
// There is a call to performAjaxValidation() commented in generated controller code.
// See class documentation of CActiveForm for details on this.
'enableAjaxValidation'=>false,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($home); ?>
<div class="row">
<?php echo $form->labelEx($image,'imageUrl'); ?>
<?php echo $form->textField($image,'imageUrl',array('size'=>60,'maxlength'=>100)); ?>
<?php echo $form->error($image,'imageUrl'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($home,'recentEvents'); ?>
<?php echo $form->textField($home,'recentEvents',array('size'=>60,'maxlength'=>100)); ?>
<?php echo $form->error($home,'recentEvents'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($home,'introduction'); ?>
<?php echo $form->textArea($home,'introduction',array('rows'=>6, 'cols'=>50)); ?>
<?php echo $form->error($home,'introduction'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($home->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
Update I had FindByattribues instead of FindAllByAttribues in the model so now it is returning an array. Now how to process that array in the view?
Okay i figured it out by myself posting this to maybe help someone who needs it. I the view i did the following.
<?php
foreach($image as $image){
?>
<div class="row">
<?php echo $form->labelEx($image,'imageUrl'); ?>
<?php echo $form->textField($image,'imageUrl',array('size'=>60,'maxlength'=>100)); ?>
<?php echo $form->error($image,'imageUrl'); ?>
</div>
<?php
}
?>

Return Key Not Working For Textarea PHP/Yii

The following is done using Yii and PHP already tried to ask on the Yii Forum but no solutions where given.
I have the following textArea in one of my views.
<div class="row">
<?php echo $form->labelEx($model,'ref_description'); ?>
<?php echo $form->textArea($model,'ref_description',array('rows'=>6, 'cols'=>50)); ?>
<?php echo $form->error($model,'ref_description'); ?>
</div>
Why isn't it able to return a newline when pressing the enter key but instead it's moving to the following textField?
Whole Code:
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'report-references-form',
'enableAjaxValidation'=>false,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'ref_name'); ?>
<?php echo $form->textField($model,'ref_name',array('size'=>60,'maxlength'=>150)); ?>
<?php echo $form->error($model,'ref_name'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'ref_description'); ?>
<?php echo $form->textArea($model,'ref_description',array('rows'=>6, 'cols'=>50)); ?>
<?php echo $form->error($model,'ref_description'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'ref_quarter'); ?>
<?php echo $form->textField($model,'ref_quarter'); ?>
<?php echo $form->error($model,'ref_quarter'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'ref_year'); ?>
<?php echo $form->textField($model,'ref_year'); ?>
<?php echo $form->error($model,'ref_year'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'ref_date'); ?>
<?php echo $form->textField($model,'ref_date'); ?>
<?php echo $form->error($model,'ref_date'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
Please suggest about anything as this thing looks really stupid and I can't seem to find a way around it tried javscript with shift+enter command and other things.
Try to disable all js code (webdeveloper addon for firefox for example).
Save to pure html page and delete particular parts. This will help you diagnose reason.
If below fail try to build pure html form without anything more than pure html tags. No css, no js.
Check your browser addons - mabye there is something.
For further help to this question regarding the Yii. What needs to be changed is in the main layout.
There is a javascript code:
$('body').on('keydown', 'input, select' , 'textarea', function(e) {
var self = $(this)
, form = self.parents('form:eq(0)')
, focusable
, next
;
if (e.keyCode == 13) {
focusable = form.find('input,a,select,button,textarea').filter(':visible:not(:disabled)');
next = focusable.eq(focusable.index(this)+1);
if (next.length) {
next.focus();
} else {
form.submit();
}
return false;
}
});
Remove the textarea from the $('body').on function ONLY!

jQuery Sortable Lists with CodeIgniter

I am attempting to make a sortable list out of list items populated from the database using the jQuery plug in but the effect is only applied to the first item presented:
<?php if(isset($bookmarks)) : foreach($bookmarks as $row) :?>
<div id="makeDrag">
<?php $fixed = preg_replace('#^[^:/.]*[:/]+#i', '', $row->URL); ?>
<li>
<div class="well">
<div><?php echo anchor('http://'.$fixed, $row->Name); ?></div>
<div><strong>Comments:</strong> <?php echo $row->Comments; ?></div>
<h4 class="btn-small">
<?php echo anchor("site/delete/$row->id", "Delete"); ?>
</h4>
</li>
</div>
<?php endforeach; ?>
I can kind of see where this is going wrong but do not know how to fix it. I would obviously like the effect to affect all the populated li not just the first one. Any help would be great. Sorry if I am unclear, I can try and rephrase things if this is confusing.
The cause is likely because you have
$('#makeDrag').sortable();
but you also have a foreach statement that creates multiple #makeDrag elements thus making your HTML invalid.
To fix this:
<?php if(isset($bookmarks)) : ?>
<ul id="makeDrag">
<?php foreach($bookmarks as $row) : ?>
<?php $fixed = preg_replace('#^[^:/.]*[:/]+#i', '', $row->URL); ?>
<li>
<div class="well">
<div><?php echo anchor('http://'.$fixed, $row->Name); ?></div>
<div><strong>Comments:</strong> <?php echo $row->Comments; ?></div>
<h4 class="btn-small"><?php echo anchor("site/delete/$row->id", "Delete"); ?></h4>
</div>
</li>
<? endforeach; ?>
</ul>
<?php endif; ?>
HTH

Categories