Yii Framework Forum: [EXTENSION] multimodelform/jqrelcopy - Yii Framework Forum

Jump to content

  • (15 Pages)
  • +
  • « First
  • 7
  • 8
  • 9
  • 10
  • 11
  • Last »
  • You cannot start a new topic
  • You cannot reply to this topic

[EXTENSION] multimodelform/jqrelcopy Solutions for clientside cloning Rate Topic: ***** 4 Votes

#161 User is offline   Andrey_ 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 13-January 12

Posted 29 April 2012 - 05:06 PM

Everything works, thanks
0

#162 User is offline   ragua 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 135
  • Joined: 23-January 12
  • Location:Paris - France

Posted 04 May 2012 - 03:43 AM

Hi,
i wanted to use jquery-tipsy to add some tooltips to the multimodel fields in my form, but it seems not work.
Does anyone try this?
0

#163 User is offline   SebK 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 40
  • Joined: 19-April 12

Posted 04 May 2012 - 04:35 AM

First off, thanks for the extension and example it comes with. I'm special though so I need help:

How do I add values so that every member that I'm creating has it? A date that I set in my php code rather than via UI would be an example. I thought the $masterValues array would be the place but it doesn't seem to work.

I also have the problem that when I try to create my form, it adds an extra instance of the member boxes and complains about validation. Any ideas what may cause that kind of behaviour, the additional box?

Is $masterValues the right place to but my values that members share? Like so:

$masterValues = array ('session_id'=>$model->id,
                                      'user_id'=>$model->user_id,
                                      'date'=>$model->date,
                                      );


If that is the case then I know I've messed up something else. Any suggestions?

Thanks

edit:
When I don't enter anything into the member form, it doesn't attempt to validate it and saves the group part. When I put in values that should validate, it doesn't accept them and creates and extra member box to fill in. I've tried to restart from scratch and somehow I've ended up with the same nonsense.
0

#164 User is offline   Joblo 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 685
  • Joined: 12-September 10
  • Location:Austria

Posted 04 May 2012 - 04:56 AM

Yes, the $masterValues should be the right place for adding values to all detail records.

if you take a look at the 'function save' , the attributes will be assigned before saving the detail model:


 public static function save($model, &$validatedItems, &$deleteItems = array(), $masterValues = array(), $formData = null)
    {
        ...
          if (!empty($masterValues))
                   $item->setAttributes($masterValues, false);
        ...
    }


'$item' is the detail model and 'setAttributes' with $safeOnly=false is used;
So you have to check the attributes of the detail model, if this doesn't work.
Try to debug through the code or do var_dump... etc. here.


Try this test release if you don't want to show the additional empty member box.
0

#165 User is offline   SebK 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 40
  • Joined: 19-April 12

Posted 04 May 2012 - 05:42 AM

Thanks for the prompt response.

The behaviour with the box makes more sense to me now (having one as default but no additions or subtractions on submit would imho be best but I have other problems ;) ).

The $masterValues still don't work. They live in the controller and I don't need to handle them anywhere else, right? I'm very new to this so I don't want to start blaming other people on things not working.

I tried removing the "deleteMembers" from MultiModelForm::save, since it seems redundant in the never version and might mess with the parameters but that didn't help either.

So now I'm lost because I'm not even sure which parts are my fault. Do people not usually use the masterValues?

I'm doing my best to find out what's wrong:
The following line is what fails:
 if( //validate detail before saving the master
                MultiModelForm::validate($member,$validatedMembers,$deleteItems)
//                && $model->save()
            )


It doesn't validate, because the fields that I want want to set via $masterValues are required. So what I did was take the $mastValue assignment out of the if clause and put it before the check occurs. Much to my surprise, this changes nothing.

This is my attempt:
$masterValues = array('session_id'=>$model->id,'date'=>1,'user_id'=>1);


I'm beyond lost. I don't even know where to look for what is going wrong. I don't know if it's the extension or my screwed up code. I might try creating a new project just to confirm the extension does what I think it does...
0

#166 User is offline   Joblo 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 685
  • Joined: 12-September 10
  • Location:Austria

Posted 04 May 2012 - 06:39 AM

Take a look at the demo app -> GroupController::actionCreate();

There the $masterValues are used to save the the foreignkey 'groupid' from the master model.
This must work, otherwise the whole demo-app will be useless.

Try to debug to check why the masterValues don't work in your application.
0

#167 User is offline   SebK 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 40
  • Joined: 19-April 12

Posted 04 May 2012 - 07:38 AM

I've figured it out, I'm not sure it's a good way to go though:

I kept getting the validation message when I tried to submit and that validation happens before the $masterValues get assigned. In order to get it to work, I've had to take the relevant fields out of the rules array where they were required.

If I understand the example code correctly, it would fail if groupid were a required field in the relevant model?!?

This is how I understand it:
=> validating the $member
MultiModelForm::validate($member,$validatedMembers,$deleteItems)

only after that $masterValues gets assignedL
$masterValues = array('session_id'=>1,'user_id'=>1,'date'=>1);


Hence when $member gets validated, it fails, if any of the fields that $masterValues fills, are required. Moving the $masterValues before the first validation doesn't work, I assume that's down to how the extension works.

Does that make sense?

I'm aware that in this case I'm setting the values so no need to validate them. However, there is another use of the same model where the input could come from the user. I guess I'm surprised at how this works.
0

#168 User is offline   Joblo 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 685
  • Joined: 12-September 10
  • Location:Austria

Posted 04 May 2012 - 07:50 AM

A possible workaround: add a specific 'scenario' when creating/validating the new detail models

//----------- NEW (on validation error) -----------
public function initItems(&$validatedItems, &$deleteItems, $masterValues = array(), $formData = null)
    {


        if (isset($formData[$modelClass]['n__']))
        {
            foreach ($formData[$modelClass]['n__'] as $idx => $attributes)
            {
                $model = new $modelClass;
                $model->scenario = 'newMultimodel' //<------- add this
                $model->attributes = $attributes;



Now in the rules of your detail model you can use 'on'=>'newMultimodel' to distinguish between standard validation and validation in the multimodelform.

If this helps, I will add the scenario line.
0

#169 User is offline   SebK 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 40
  • Joined: 19-April 12

Posted 04 May 2012 - 08:16 AM

edit: as it turns out I'll have to some up with my own solution because my situation is a little more complicated. I'll be looking at your work for inspiration but you don't need to add anything for my sake.

Cheers

I guess it would add flexibility and give people a choice as to how they want to deal with scenarios. I think it would be useful but you have to judge to what extent what I'm doing is just stupid ;)

If you want me to test anything let me know. I may need a sample rule to really understand how it works though.

I think I can work with what I have now so if you're busy don't worry.

Thanks for your time!

0

#170 User is offline   ragua 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 135
  • Joined: 23-January 12
  • Location:Paris - France

Posted 10 May 2012 - 02:24 AM

Auto-response: i use the title properties instead of tooltips.

View Postragua, on 04 May 2012 - 03:43 AM, said:

Hi,
i wanted to use jquery-tipsy to add some tooltips to the multimodel fields in my form, but it seems not work.
Does anyone try this?

0

#171 User is offline   pagondel 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 18-September 11

Posted 19 June 2012 - 05:14 PM

View PostTh3 R00ST3R, on 06 April 2012 - 10:33 AM, said:

Hi,
I don't think this is a MMF issue, but I didn't know where else to post this..

I have one last piece and I think my form will be complete. I want to put the multimodelform into a cJuiTabs.
When I put the widget into the tab, It doesn't put it in the tab, but above it.
Can someone point me in the right direction?
$this->widget('zii.widgets.jui.CJuiTabs', array(
        'tabs'=>array('Standard 1'=>array($this->widget('ext.multimodelform.MultiModelForm',array(
                      'id' => 'id_perfreviewsub2', //the unique widget id
                      'formConfig' => $perfreviewsubFormConfig, //the form configuration array
                      'model' => $perfreviewsub, //instance of the form model
                      
                      //if submitted not empty from the controller,
                      //the form will be rendered with validation errors
                      'validatedItems' => $validatedPerfReviewSub,
                      'tableView' => true,
               
                      //array of perfreviewsub instances loaded from db
                      'data' => $perfreviewsub->findAll(array(
                              'condition' => 'performancereviewid=:performancereviewid and standardid=:standardid',
                              'params' => array(':performancereviewid'=>$model->performancereviewid,':standardid'=>1,),
                              'order' => 'standardid, elementid ' ))
                  ))),
    ),
    // additional javascript options for the tabs plugin
    'options'=>array(
        'collapsible'=>false,
    ),
));


Thank you very much.


Maybe it's too late, but it may help someone... When you do the renderPartial you need to add a true in the end, indicating that the result must be returned instead of rendered...
Here its an example:
'Paso 4'=>$this->renderPartial('pasoCuatro',array('form'=>$form,'model'=>$model,'detalleVenta'=>$detalleVenta,'detallesValidos'=>$detallesValidos),true),

0

#172 User is offline   diego_2002ec 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 15-March 12

Posted 20 June 2012 - 06:49 PM

Hi Joblo,

I am using this extension and it's great.

Is possible to use jquery in detail model ?

Example;

In detail model (Detall Bill)
I have one input text (Item Code), after to input this field I need to show How many items are in stock model

Any ideas?


0

#173 User is offline   elix 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 14-February 12

Posted 27 June 2012 - 12:05 AM

Mr. Joblo

This is a great extension.

Sorry for my english.
I get autocomplete to work. May be you will had it to the next version.

What i notice :
1- .autocomplete() won't apply on the clone input
2- .autocomplete() wont work unless the input field is added to the page

What i've done :
1- .autocomplete() won't apply on the clone input
1-1 add a new input with same id and name
1-2 remove old input
1-3 apply .autocomplete() on new input

 public static function whenDoneAutoComplete($element, $idElement)
    {
        $options = isset($element['options']) ? $element['options'] : array();
        if (isset($element['sourceUrl']))
            $options['source'] = CHtml::normalizeUrl($element['sourceUrl']);
        else
            $options['source'] = $element['source'];

        $jsOptions = CJavaScript::encode($options);

	return "
		var acID=this.attr('id');
		if(acID.indexOf('".$idElement."')>=0)
		{
			var acName=this.attr('name');
			this.after('<input id=\"'+acID+'\" name=\"'+acName+'\"  type=\"text\">');
			this.remove();
			$('#'+acID).autocomplete(".$jsOptions.");
		}
	";
    }

But for this to work we have to give the name of the attribute to be treated ($idElement). So by now it will only work with one autocomplete. Need to review in order to handle an array of attributes name.

2- .autocomplete() wont work unless the input field is added to the page
2-1 add a new js options (jsWhenDone)
2-2 change jquery.relcopy.yii.3.3.js to handle whenDone new option
$(parent).find(rel+':last').after(clone);
$(clone).find('[id]').each(function(){
	funcWhenDone.call($(this));
});

At this step i ran into a strange issue. the autocomplete of the master template stop working after adding more copies although all the AC from copies work well.
To correct this i decided to use the master template only for cloning and change relcopy like this
/*if(!master.is(":visible"))
{
   master.show();
   mmfRecordCount++;
   return;
}*/

...

$(parent).find(rel+':last').after(clone);
$(clone).show();
$(clone).find('[id]').each(function(){
	funcWhenDone.call($(this));
});


Perhaps it isn't the best way to do it but it works great for me.

I also change mmf to handle composit PK but do it qickly to get it working. May have some issues on delete with simple PK.

Hope this helps.

see attached files for complete changes

Attached File(s)


0

#174 User is offline   andjelko 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 08-February 12

Posted 12 July 2012 - 04:52 AM

When I add a new row in tableView after a few rows option delete rows are duplicate???
Why is that?

Is anyone can help me?

Cheers.
0

#175 User is offline   Davjack 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 17-November 11

Posted 13 July 2012 - 02:40 AM

Thanks you Elix for your "composite PK" add-on. It works very well.

Apparently, it is currently not possible to put several detail elements (eg, a Group of Members and Missions). The problem is that the widget can not distinguish the two elements in the number of records (if you add a member and a mission to a group, the widget think there are two members and two missions).

Has someone a solution for this problem?
0

#176 User is offline   vibhaJadwani 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 32
  • Joined: 13-June 12
  • Location:India

Posted 16 July 2012 - 08:29 AM

Thanks for this extension.
I am having one issue, 'Remove' text is repeated as shown in attachment.
Can anyone please help?
Attached File  double.png (5.08K)
Number of downloads: 36
0

#177 User is offline   Joblo 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 685
  • Joined: 12-September 10
  • Location:Austria

Posted 16 July 2012 - 08:59 AM

This is an issue if 'tableView'=>true and 'hideCopyTemplate' => true.
I have to investigate this.

At the moment you have to set 'hideCopyTemplate' => false, if you use the tableView.
1

#178 User is offline   vibhaJadwani 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 32
  • Joined: 13-June 12
  • Location:India

Posted 16 July 2012 - 09:18 AM

View PostJoblo, on 16 July 2012 - 08:59 AM, said:

This is an issue if 'tableView'=>true and 'hideCopyTemplate' => true.
I have to investigate this.

At the moment you have to set 'hideCopyTemplate' => false, if you use the tableView.

Thanks Joblo.. It worked! +1 :)
0

#179 User is offline   ragua 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 135
  • Joined: 23-January 12
  • Location:Paris - France

Posted 23 July 2012 - 04:11 AM

Hi, i'm having troubles with dropdownlist in multimodelform.
When i load datas, i want that only some values appears for the user, in function of another field value.
This is partof my form:
<?php  
$model3 = RelStudentSemester::model()->findAll(array('condition'=>"group_id = " .  $model->group_id, 'order' => 'student_lastname, student_firstname'));
	$data3 = array();
	foreach ($model3 as $models){
		if($models->resit == 2)
		{
	 		$data3[$models->student_id] = array(2=>'Rattrapage');
		}
		elseif($models->resit == 1)
		{
	 		$data3[$models->student_id] = array(1=>'Hors rattrapage');
		}
		elseif($models->resit == 0)
		{
 		        $data3[$models->student_id] = array(0=>'Non renseigné');
		}
		else
		{
			$data3[$models->student_id] = array(3=>'A renseigner', 1=>'Hors rattrapage', 2=> 'Rattrapage');
		}
	} ?>
...

<?php   $relStudentSemesterFormConfig = array(
      'elements'=>array(
...
        'resit'=>array(
            'type'=>'dropdownlist',
		'items' => $data3,
        ),
...


When page load, i seee the correct value of the field (resit / rattrapage) but when i open the dropdownlist all values appears (see the attached file)...
Can someone help me with this?
0

#180 User is offline   ragua 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 135
  • Joined: 23-January 12
  • Location:Paris - France

Posted 23 July 2012 - 04:12 AM

Oups, i forgot the file...

Attached File(s)


0

Share this topic:


  • (15 Pages)
  • +
  • « First
  • 7
  • 8
  • 9
  • 10
  • 11
  • Last »
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users