[EXTENSION] wForm

WHY THE EXAMPLE DO NOT HAVE BEHAVIOR?

Do you mean product example sources? If so, then why extension should be places into example which located INTO EXTENSION?

Hi, Thanks for nice extension.

I tried your product example, but delete images (attachment) doesnt work.

I click on delete link (jquery remove elements), but after submnit product form, images records are still there.

Any idea?

Not implemented this function yet?

Marena

Hi Marena,

Thanks for your reply.

You are right. Removing of related records is not working properly yet. It will be ready in the next extension version which we plan to get done during next week. BTW, there would be also cascade delete to allow remove products with all necessary relations.

Regards,

Alex

Weavora Team

Hi Alex

Thanks again,

I’ll wait for next version.

Meanwhile I’ll edit javacript in existing version. Instead of js delete element, just hide it and set hidden field “deleted” to 1 (because in some tables I dont want to delete an records (for history issues), but only set to deleted)

Have a nice weekend,

Marena

Hi Alex,

Just ideas for you what changes I made to satisfied my needs.

I made some changes in jquery.multiplyforms.js

  1. option to choose between .appendTo / .prependTo (in some forms I prefer add new rows at the beginning)

  2. I change beforeDelete callback to (I needed to just hide records in database - not delete)




// beforeDelete callback

// I know - now its replace delete

if ($.isFunction(self.options.beforeDelete)) {

  self.options.beforeDelete.call(this, embedForm, self);

} else {

   embedForm.remove();

}




// in form i call

beforeDelete: function(embedForm, multiplyFormInstance){

  if (confirm("Are you sure to delete this record?")) {

    embedForm.find('input[id$="valid"]').val(0);

    embedForm.css('display','none');

  } else {

    return false;

  }

}




Have a nice day

Marena

(sory for google translator english)

Hi Marena,

Thnx for good ideas.

We’ll add appendMode option with possible values: ‘append’ or ‘prepend’

You are absolutely right there. That’s why we should move to jquery events instead of callbacks. So finally your code will look like:




$('.hasManyRelation')

  .multiplyForms({

    embedClass: 'has-many-item',

    templateClass: 'just-empty-form-template-hasManyRelation'

  })

  .on('multiplyForms.add', function(event, embedForm, multiplyFormInstance){})

  .on('multiplyForms.delete', function(event, embedForm, multiplyFormInstance){

    event.preventDefault(); // callback-killer feature <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/smile.gif' class='bbc_emoticon' alt=':)' />

    if (confirm("Are you sure to delete this record?")) {

      embedForm.hide().find('input[id$="valid"]').val(0);

    }

  });



Also it will allow bind/unbind add/remove handlers in other places of the code.

Best regards,

Alex

Thanks for reply Alex and good luck with new version.

Version 0.2 released

Change log:

  • Cascade delete

  • Remove old related item during update

  • Multiple bug fixes

  • jQuery plugin: append mode

  • jQuery plugin: replace callbacks with events

Hi, Thank you for this nice extension O0

Did the v 0.2 manage the add/update/delete process in a transaction?

the version I downlowa few days ago seems not! am I wrong? (hope yess, because this extension will make my life easier if it do manage transactions)

Hi,

I with to say ‘yes’, but wForm doesn’t support transactions for now. But that’s a good feature for next release.

For now you could try temporal hook:





public function actionEdit($id = null) {

  ...

  if ($yourForm->validate()) {

    $transaction = Yii::app()->db->beginTransaction();

    if ($yourForm->save()) {

      $transaction->commit();

      $this->redirect(..);

    } else {

      $transaction->rollback();

    }

  ...

}



Hi,

I see that I am more concentrated on looking for extensions that make my life easier OutOfTheBox then traying to adapt solution to my needs, [sup]ehhmmm, maybe there is somethings to reconsidere here…[/sup]

or perhaps transactions in multidependent inserts is something MusHaveOutFromTheBox.

I definitely agree with you, I think it’s a good feature to have, maybe with autodetecting for transactions support in databases.

Thank you again.

Hi,

You have something verry interesting here to manage related models, I t hink your extension can be improved with this behavior

https://github.com/y...elated-behavior

just trying it for now, but it look awsome for me.

Hello,

does WUNIT support testing AJAX requests?

(or to be precise - invoking and processing javascript events?)

Example:

I have a form with 2 dropdown boxes.

When I select option in first dropdown, then ajax is invoked and populates second dropdown box.

As far as I know Selenium is the only tool capable of invoking AJAX requests.

Does WUnit somehow support this magic and can fully replace Selenium server?

Thank you.

Lubos

A try it, my input look nice. But when I want to save, I have this error.

Fatal error: Call to a member function validate() on a non-object in /var/www/html/senik/app/protected/extensions/wform/WFormRelationHasOne.php on line 32

The function getRelatedModel return an array and not a model object ?

That’s quite strange. It could only if you put not well-formatted data into HAS_ONE model. E.g. not [name => 123], but [0 => [name => 123]]

I tried out.

I want to include js/jquery.multiplyforms.js in my layout file, but it seems not to work. Normally the js-file should automatically copied in the asset-folder, or?

In the assets-folder is no jquery-multiplyforms.js. The result is that “delete” and “add” doesn’t work for me. :frowning:

Thx

Is "attaching behavior" necessary ?

If I attach the behavior I get an error like this one: “Illegal offset type in isset or empty”. Maybe there is a Problem, because the PK of one table hast two columns. But I don’t know how setup this.

A short reply would help me.

After some tests: Your extension does not support a PK which hast two colums. Only the ManyManyRelation allows this. So the wform extension is not helpful for me, because I have a HasManyRelation, where the PK hast two Columns and only one of these two columns is a FK.

Thanks a lot WeaVora Team, for this grate extension.

Easy to use, and with very clear documentation and examples.

My question is in the example given here https://github.com/weavora/wform/wiki/Example:-Product-form

is it possible to add other information to "product_2_tag" table, suppose I want to add "product_tag_serial_no" for every entry in "product_2_tag".

I struct with this problem Please help me out.

Hi,

I have been trying to implement a HAS_MANY relationship for a while now and just cant seem to get it to work properly, data will display perfectly but i am unable to save back to the DB.

I keep receiving the following error when trying to save.

Fatal error: Call to a member function relations() on a non-object in C:\Program Files (x86)\EasyPHP-5.3.9\www\mysite\protected\extensions\wform\WForm.php on line 284

What I am building is a bird identification db, the update page has all the information about a particular type of bird, along with key points (BirdNotes) and a multiple images of the bird (Photos), the Photos table also has a relation to another table for storing the image itself.

I have gone through and looked at the example included but I am unable to make it work. The same error will appears no matter which HAS_MANY relationship I put on the form.

All models are standard as generated using Giix

Any help would be appreciated.

Here is my Relations in the Model


public function behaviors() {

        return array(

            // attach wform behavior

            'wform' => array(

                'class' => 'ext.wform.WFormBehavior',

                // define relations which would be processed

                'relations' => array('idNativity0', 'idProtection0', 'idHabitat0', 'BirdNotes', 'Photos'),

            ),

        );

    }


public function relations() {

		return array(

			'idNativity0' => array(self::BELONGS_TO, 'Nativity', 'idNativity'),

			'idProtection0' => array(self::BELONGS_TO, 'Protection', 'idProtection'),

			'idHabitat0' => array(self::BELONGS_TO, 'Habitat', 'idHabitat'),

			'BirdNotes'=> array(self::HAS_MANY, 'BirdNote', 'idBird'),

			'Photos'=> array(self::HAS_MANY, 'Photo', 'idBird'),

		);

	}



Here is my Controller


	public function actionUpdate($id = null)

	{

		$model = $id ? Bird::model()->with('idNativity0', 'idProtection0', 'idHabitat0', 'BirdNotes', 'Photos')->findByPk($id) : new Bird();

		

		$model=$this->loadModel($id);


		if(isset($_POST['Bird']))

		{

			$model->attributes=$_POST['Bird'];

			

			if($model->save()) {

				

				$this->redirect(array('view','id'=>$model->idBird));

			}

		}


		$this->render('update',array(

			'model'=>$model,

		));

	}

Here is the Form for the BirdNote portion


<div class="row clearfix hasManyRelation">

	<strong>Interesting Facts</strong>

		<!-- exists items -->

		<?php if ($model->BirdNotes): ?>

			<?php foreach ($model->BirdNotes as $index => $item): ?>

				<div class="has-many-item clearfix" style="background-color:#E4E4E4;padding:5px;margin-top:5px;">

					<div style="float:left;">

						<?php if (!$item->isNewRecord): ?>

							<?php echo $form->hiddenField($model, "BirdNotes.{$index}.idBirdNote"); ?>

						<?php endif; ?>

						<?php echo $form->labelEx($model, "BirdNotes.{$index}.Note"); ?>

						<?php echo $form->textField($model, "BirdNotes.{$index}.Note",array('size'=>50,'maxlength'=>255)); ?>

						<?php echo $form->error($model, "BirdNotes.{$index}.Note"); ?>

					</div>

					<div style="float:left;margin-left:10px;width:50px;text-align:center;">		

						<?php echo $form->labelEx($model, 'BirdNotes..Active'); ?>

						<?php echo $form->checkBox($model, 'BirdNotes..Active'); ?>

						<?php echo $form->error($model, 'BirdNotes..Active'); ?>

					</div>

					<div style="float:right;margin-left:10px;">

						<a href="#" class="delete">Delete</a>

					</div>

				</div>

			<?php endforeach ?>

		<?php endif; ?>

	 

		<!-- create new items -->

		<div style="display:none;" class="has-many-item just-empty-form-template-hasManyRelation">

			<div class="clearfix" style="background-color:#E4E4E4;padding:5px;margin-top:5px;">

				<div style="float:left;">

					<?php echo $form->labelEx($model, 'BirdNotes..Note'); ?>

					<?php echo $form->textField($model, 'BirdNotes..Note'); ?>

					<?php echo $form->error($model, 'BirdNotes..Note'); ?>

								

					<?php echo $form->labelEx($model, 'BirdNotes..Active'); ?>

					<?php echo $form->checkBox($model, 'BirdNotes..Active'); ?>

					<?php echo $form->error($model, 'BirdNotes..Active'); ?>

					<br />

					<a href="#" class="delete">Cancel</a>

				</div>

			</div>

		</div>

	 

		<a href="#" class="add">Add Note</a>

	</div>



--------- SOLVED ----------

Managed to locate the problem, for some reason the installation of PHP I have was not replacing the index variable in the string "BirdNotes.{$index}.Note" and putting in the index, neither that or "BirdNotes.$index.Note" worked, once I changed it to "BirdNotes." . $index . ".Note" everything came right.

I also added the following to line 284 of wForm.php, this will fix the array so that a CException is thrown for the invalid relation name, in my case it was throwing {index}




if (empty($model->relations)) { $model = array_shift(array_values($model)); }