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

Jump to content

  • (14 Pages)
  • +
  • « First
  • 2
  • 3
  • 4
  • 5
  • 6
  • Last »
  • You cannot start a new topic
  • You cannot reply to this topic

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

#61 User is offline   A.Miguel 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 12-October 11

Posted 13 November 2011 - 03:29 PM

Hi Joblo,


Thanks for your valuable inputs.

View PostJoblo, on 11 November 2011 - 02:37 AM, said:

A.Miguel: I think it should be possible.


1. Lets giix do the job for the form/controller for the order and the categories related to the order (checkboxes).
Comment the tbl_order_categories before creating the CRUD with the help of giix, so that the code for OrderProduct in the form/controller will not be created.

2. Add the code for the multimodelform (= detail = order_product) manually.

Add a 'getMultiModelForm' method to your OrderProduct model.

Something like this:

- Add the multimodelform widget in the form:
The '$member' from the documentation is your OrderProduct model.

- Add the multimodelform code to save/validate the multimodel data similar to the one in the documentation.
$model = Order, $member = $orderProduct ($validatedOrderProduct ...).

Maybe try first with 'MultiModelForm::save' only and add 'MultiModelForm::validate' later.

- Hint: do var_dump in the actionCreate to see whats comming in, will be validated ...



Your suggestion works fine for actionCreate. But for actionUpdate MultiModelForm code would require an update...

Since my tbl_order_products primary key is a composite key (order_id, product_id) MultiModelForm code fails when extracting the primary key from this table:
PHP Error

Illegal offset type

C:\...\extensions\multimodelform\MultiModelForm.php(523)


   $pkValue = $model->primaryKey;
   if (!empty($pkValue))
   {
      $pkName = $model->primaryKey();
      if (empty($pkName))
         $pkName = $model->tableSchema->primaryKey;
 
->    $result = array($pkName => $pkValue);
   }



Is this a bug or your extension is not supposed to work with composite keys?

Can you please provide me a workaround for this?


Thanks for your support,
A.Miguel
0

#62 User is offline   Joblo 

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

Posted 13 November 2011 - 04:28 PM

I know that the multimodelform (at the moment) only supports a single primary key.
This is no bug.
I have implemented this, because Yii's CRUD doesn't support a composite PK out of the box (loadByPK).

But you are right, maybe a code modification in the method getPrimaryKey() is enough to add the support for a composit PK because CActiveRecord supports this.

Can be something like this - but not tested.
public function getPrimaryKey($model)
{
	$result = array();

	if ($model instanceof CActiveRecord)
	{
		
		$pkName = $model->primaryKey();
		if (!empty($pkName))
		{
			if (is_array($pkName))
			{
				foreach ($pkName as $pk)
				  if (isset($model->$pk))
					$result[] = array($pk => $model->$pk);
			}
			else
			{
				$pkValue = $model->primaryKey;
				$pkName = $model->tableSchema->primaryKey;
				if (isset($pkValue))
				   $result = array($pkName => $pkValue);
			}
				
		}
	}
	else // when working with EMongoDocument
		if (method_exists($model, 'primaryKey'))
		{
			$pkName = $model->primaryKey();
			$pkValue = $model->$pkName;
			if (empty($pkValue))
				$result = array($pkName => $pkValue);
		}

	return $result;
}


But you have to test:

line 744: renderHiddenPk - will work for composit PK
line 286: $item->save() - should work too with composit PK
line 291: needs testing
if (!empty($deleteItems))
foreach($deleteItems as $pk)


Sorry, I have no time in the moment to build a test enviroment for this, but your code seems to be one ;-)
So, if you do the modification(s) and send me your working/tested new code of the multimodelform, I will add this to the next release.
0

#63 User is offline   soulache 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 13-July 11

Posted 20 November 2011 - 02:14 PM

Hello Joblo!

Thank you for plugin! Wish you having time and strength to continue supporting this plugin!

Also I have one question: is it possible to clone several model input fields, but not all of them?
For example, if I have 10 input fields, and 7 of them are "static" (text will be entered only once) and another 3 will be copied by pressing "add item".

Thanks in advance
0

#64 User is offline   Joblo 

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

Posted 20 November 2011 - 02:54 PM

I didn't test it, but should be possible.

Take a look at the documentation of the integrated jqrelcopy jQuery plugin

There exists the property 'excludeSelector' and you can set the jqrelcopy-properties through the 'options' property of the multimodelform widget.

 $this->widget('ext.multimodelform.MultiModelForm',array(
       ...
        'options'=>array('excludeSelector'=>'YourExcludeSelector'),
       ...
    ));



But maybe this will have sideeffects on building the items-arrays on validate/save... and needs more workaround.
0

#65 User is offline   soulache 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 13-July 11

Posted 21 November 2011 - 02:17 PM

View PostJoblo, on 20 November 2011 - 02:54 PM, said:

I didn't test it, but should be possible.
...
There exists the property 'excludeSelector' and you can set the jqrelcopy-properties through the 'options' property of the multimodelform widget.
But maybe this will have sideeffects on building the items-arrays on validate/save... and needs more workaround.



Please correct me if I'm doing something wrong.
Here is my code:

$techFormConfig = array(
      'elements'=>array(
        'tech_channel_id'=>array(
            'type'=>'text',
            'maxlength'=>50,
            'rel'=>'tech_channel_id',
        ),
   ....
   ....
);

$this->widget('ext.multimodelform.MultiModelForm',array(
        'id' => 'id_tech', //the unique widget id
        'formConfig' => $techFormConfig, //the form configuration array
        'model' => $tech, //instance of the form model
        'options' => array('excludeSelector' => 'tech_channel_id'),
    ...
    ...
    ));


And these lines are not working...
When i click "add item" the whole form is added, ignoring the 'excludeSelector'
0

#66 User is offline   Joblo 

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

Posted 22 November 2011 - 01:00 PM

The excludeSelector is a jQuery selector, that means:

- use '#tech_channel_id' if its a element with id="tech_channel_id"
- use '.tech_channel_id' if its a element with class="tech_channel_id"

your code from above will exclude all tags: <tech_channel_id>...</tech_channel_id>
0

#67 User is offline   IRCSASW 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 65
  • Joined: 01-September 11
  • Location:Cancún, México.

Posted 22 November 2011 - 09:22 PM

Hi Joblo, excellent work, congratulations!

One question, how I can do to change the form view related record, I have many fields and I want them for example in groups of three or more in vertical?, something like what is shown in the picture. is it possible?

thanks for the help and sorry for my google-English :rolleyes:

Attached File(s)


Arturo Ramos
www.ircsasoftware.com.mx
Cancún, México
0

#68 User is offline   Mr D 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 217
  • Joined: 18-May 11

Posted 22 November 2011 - 11:43 PM

hi joblo...

I use your extension multimodelform
and success ..
I want to change the appearance of:
firstName: inputField
lasName: inputField

FirstName: inputField
LastName: inputField
Remove

be like this

FirstName-------LastName-------action
inputField--------InputField--------
inputField--------InputField--------Remove


where do I need to change .. I've read MultiModelForm.php but still do not understand .. :huh:
thanks in advance for the extension... :)
Boss: "We found a bug in your code!"
Programmer: "That's no bug, that's just an undocumented feature!"
0

#69 User is offline   Joblo 

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

Posted 23 November 2011 - 02:29 AM

At IRCSASW:

Because you have to use the Yii formbuilder you have to work with the features of the CForm and the CFormInputElement.

I didn't test this, but you should be able to specify the layout property and add additional tags.

Maybe you can wrap elements into a div tag with style: float left.

$formConfig = array(
      'elements'=>array(
        
        <div style="float:left">, 

          'elem1'=>array(
            'type'=>'text',
            'maxlength'=>2,
            'layout'=>'<div ...> ...{label} {input}...</div>',
          ),
        .... more elements

        '</div>',
);



So you have to play around with additional div tags and css.
0

#70 User is offline   Joblo 

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

Posted 23 November 2011 - 02:32 AM

At Mr D:

You can use the 'tableView' feature:

$this->widget('ext.multimodelform.MultiModelForm',array(
       ...
        'tableView' => true,
     //'tableFootCells' => array('footerCol1','footerCol2'...), //optional table footer
       ...
    ));


If this is not enough you have to play around with the features of CForm - see my answer to IRCSASW above.
0

#71 User is offline   Mr D 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 217
  • Joined: 18-May 11

Posted 23 November 2011 - 02:39 AM

View PostJoblo, on 23 November 2011 - 02:32 AM, said:

At Mr D: You can use the 'tableView' feature:
 $this->widget('ext.multimodelform.MultiModelForm',array(    	...     	'tableView' => true,  	//'tableFootCells' => array('footerCol1','footerCol2'...), //optional table footer    	... 	)); 
If this is not enough you have to play around with the features of CForm - see my answer to IRCSASW above.

that's what I want ... thank you very much :D :D

how to rename the header name??
Attached File  untitled.PNG (6.81K)
Number of downloads: 72

I hope autocomplete can be used immediately :P
Boss: "We found a bug in your code!"
Programmer: "That's no bug, that's just an undocumented feature!"
0

#72 User is offline   Joblo 

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

Posted 23 November 2011 - 03:25 AM

You can set the property 'label' of the elements in the formConfig to change the header.

autocomplete - sorry :-(

See my note at the extensions page:

Note: I couldn't get Autocomplete working. Maybe one of you has an idea (see afterNewIdAutoComplete in MultiModelForm.php).
0

#73 User is offline   IRCSASW 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 65
  • Joined: 01-September 11
  • Location:Cancún, México.

Posted 23 November 2011 - 01:04 PM

View PostMr D, on 23 November 2011 - 02:39 AM, said:

that's what I want ... thank you very much :D :D

how to rename the header name??
Attachment untitled.PNG

I hope autocomplete can be used immediately :P


Can you show me how you did so that the fields shown in this way?, as the image samples.

Tks.
Arturo Ramos
www.ircsasoftware.com.mx
Cancún, México
0

#74 User is offline   Mr D 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 217
  • Joined: 18-May 11

Posted 23 November 2011 - 09:38 PM

View PostIRCSASW, on 23 November 2011 - 01:04 PM, said:

Can you show me how you did so that the fields shown in this way?, as the image samples.

Tks.


$this->widget('ext.multimodelform.MultiModelForm',array(
'tableView' => true,////just add this

'id' => 'id_member', //the unique widget id
'formConfig' => $memberFormConfig, //the form configuration array
'model' => $cbcparam, //instance of the form model

//if submitted not empty from the controller,
//the form will be rendered with validation errors
'validatedItems' => $validatedMembers,

//array of member instances loaded from db
'data' => $cbcparam->findAll('id_cbc=:id_cbc', array(':id_cbc'=>$model->id)),
));
?>
Boss: "We found a bug in your code!"
Programmer: "That's no bug, that's just an undocumented feature!"
0

#75 User is offline   IRCSASW 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 65
  • Joined: 01-September 11
  • Location:Cancún, México.

Posted 23 November 2011 - 10:04 PM

Ok, thank you, that I have it, I confused what I want is that the child form is seen in blocks, each item.

keep trying with the proposal of joblo that it does not work. >:(

Attached File(s)


Arturo Ramos
www.ircsasoftware.com.mx
Cancún, México
0

#76 User is offline   IRCSASW 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 65
  • Joined: 01-September 11
  • Location:Cancún, México.

Posted 23 November 2011 - 10:32 PM

View PostJoblo, on 23 November 2011 - 02:29 AM, said:

At IRCSASW:

Because you have to use the Yii formbuilder you have to work with the features of the CForm and the CFormInputElement.

I didn't test this, but you should be able to specify the layout property and add additional tags.

Maybe you can wrap elements into a div tag with style: float left.

$formConfig = array(
      'elements'=>array(
        
        <div style="float:left">, 

          'elem1'=>array(
            'type'=>'text',
            'maxlength'=>2,
            'layout'=>'<div ...> ...{label} {input}...</div>',
          ),
        .... more elements

        '</div>',
);



So you have to play around with additional div tags and css.


Thanks Jobo,

...ignores everything that I put as text in the array of elements:
$rfqitemFormConfig = array(
  'elements'=>array(
  '<div class="width-100 fltlft"><div class="width-50 fltlft">',
  
  'estado'=>array(
    'type'=>'dropdownlist',
    'items'=>Rfqitems::model()->getEstadosPartida(),
    'layout'=>'<div class="width-50 fltlft">{label}{input}{hint}{error}</div>',
  ...	        	),


result:
...
<div class="row">
  <label for="RfqItems_estado">Estado</label>
  <div class="width-50 fltlft">
    <select id="RfqItems_estado" name="RfqItems[estado][]">
  </div>
</div>
...


and what I put like 'layout' of each element that has no effect, automatically puts a:
<div class="row"> 
  ... 
</div>


addition to the label element is not within the format of the 'layout'

any idea?
Arturo Ramos
www.ircsasoftware.com.mx
Cancún, México
0

#77 User is offline   Mr D 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 217
  • Joined: 18-May 11

Posted 24 November 2011 - 12:57 AM

hi ... i tried to make the table
tbl_cbc
-id
-name

tbl_cbc_param
-id_cbc
-time

actionUpdate

	  Yii::import('ext.multimodelform.MultiModelForm');
 
	$model=$this->loadModel($id); //the Group model
 
	$cbcparam = new CbcParam;
	$validatedMembers = array(); //ensure an empty array
 
	if(isset($_POST['Cbc']))
	{
    	$model->attributes=$_POST['Cbc'];
 
    	//the value for the foreign key 'groupid'
    	$masterValues = array ('id_cbc'=>$model->id);
 
    	if( //Save the master model after saving valid members
        	MultiModelForm::save($cbcparam,$validatedMembers,$deleteMembers,$masterValues) &&
        	$model->save()
       	)//what the contents of $deleteMembers
            	$this->redirect(array('view','id'=>$model->id));
	}
 
	$this->render('update',array(
    	'model'=>$model,
    	//submit the member and validatedItems to the widget in the edit form
    	'cbcparam'=>$cbcparam,
    	'validatedMembers' => $validatedMembers,
	));


_form
$memberFormConfig = array(
  	'elements'=>array(
    	'param_type'=>array(
        	'type'=>'dropdownlist',
        	'items'=>array(''=>'-Pleace Choose One--',1=>'IP Address',2=>'Channel'),
    	),
    	'param_value'=>array(
        	'type'=>'text',
        	'maxlength'=>40,
    	),
	
		
	));
 
	$this->widget('ext.multimodelform.MultiModelForm',array(
    	'id' => 'id_member', //the unique widget id
    	'formConfig' => $memberFormConfig, //the form configuration array
    	'model' => $cbcparam, //instance of the form model
 
    	//if submitted not empty from the controller,
    	//the form will be rendered with validation errors
    	'validatedItems' => $validatedMembers,
 
    	//array of member instances loaded from db
    	'data' => $cbcparam->findAll('id_cbc=:id_cbc', array(':id_cbc'=>$model->id)),
	));

when create success, but when the update and I did not add any data and I click save, the data is stored twice with the same ...
but when i test with a sample that is in extension, run smoothly

What did I miss?
Boss: "We found a bug in your code!"
Programmer: "That's no bug, that's just an undocumented feature!"
0

#78 User is offline   Mr D 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 217
  • Joined: 18-May 11

Posted 25 November 2011 - 01:41 AM

My problem is that my table has no pk

and how to handle it other than adding a PK at my table??
Boss: "We found a bug in your code!"
Programmer: "That's no bug, that's just an undocumented feature!"
0

#79 User is offline   Joblo 

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

Posted 25 November 2011 - 03:32 AM

View PostMr D, on 25 November 2011 - 01:41 AM, said:

My problem is that my table has no pk

and how to handle it other than adding a PK at my table??



There can't be a correct update without a primary key, because multimodelform uses the standard CActiveRecord.save, means CActiveRecort.update.

But you can define a PK in your model by adding a method 'primaryKey'. Yii will call this method to get the PK if there is no pk-definition in the table schema.

	
	public function primaryKey()
	{
		return 'myPKFieldname';
	}


0

#80 User is offline   Mr D 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 217
  • Joined: 18-May 11

Posted 25 November 2011 - 04:24 AM

how to change the position of "Add Item" to be next to "Remove" in the last row
like this pic

Attached File  ask.JPG (9.37K)
Number of downloads: 54

I tried to read the code from the MultiMoldeForm.php, but because my knowledge is still lacking so I do not understand at all :(
Boss: "We found a bug in your code!"
Programmer: "That's no bug, that's just an undocumented feature!"
0

Share this topic:


  • (14 Pages)
  • +
  • « First
  • 2
  • 3
  • 4
  • 5
  • 6
  • Last »
  • You cannot start a new topic
  • You cannot reply to this topic

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

  1. raiethan