admin管理员组文章数量:1401499
I never used Javascript before but now I need it in my Symfony-Project (Symfony 1.4) and have some problems about where to add code to get it working:
I have a template (indexSuccess) in the module „aktionLimit“ where I show the values of the variables of an Object of the class „Aktion“ :
<p>Value1: <?php echo $aktion->getValue1() ?></p>
<p>Value2: <?php echo $aktion->getValue2() ?></p>
<p>Value3: <?php echo $aktion->getValue3() ?></p>
<?php include_partial('form', array('form' => $form)) ?>
This is the executeIndex:
$this->aktion = AktionlimitPeer::getByName($this->getUser()->getAttribute('aktion'));
$aktionParam = new Aktion();
$aktionParam->setName($this->aktion->getName());
$this->form = new AktionlimitForm(array(), array("aktion" => $aktionParam));
The AktionLimitForm looks like this:
$aktionForm = new AktionForm($this->getOption('aktion'), array("limit" => true));
$this->embedForm('Aktion', $aktionForm);
$this->widgetSchema['neuerWert']= new sfWidgetFormInputText();
The embedded AktionForm has just one element (a dropdown-box which includes the unique names of the objects of „Aktion“):
$this->widgetSchema['name'] = new sfWidgetFormChoice(array('choices' => AktionPeer::getTypes()),array('onchange' => '???'));
Whenever the user chooses another „aktion“ in the dropdown-box I want to load the current object „aktion“ (referenced by the name) in executeIndex and show its values (Value 1-3) in indexSuccess.(When submitting it leads to another action.)
I need a function which calls executeIndex in the onChange-Event. I probably have to declare the function in the web/js-folder, is this right?. But how do I call the function from the form? And how do I call an action in a JavaScript-Function?
I hope you understood what I've written – today I have some difficulties to explain this problem in English :) Could anybody help?
I never used Javascript before but now I need it in my Symfony-Project (Symfony 1.4) and have some problems about where to add code to get it working:
I have a template (indexSuccess) in the module „aktionLimit“ where I show the values of the variables of an Object of the class „Aktion“ :
<p>Value1: <?php echo $aktion->getValue1() ?></p>
<p>Value2: <?php echo $aktion->getValue2() ?></p>
<p>Value3: <?php echo $aktion->getValue3() ?></p>
<?php include_partial('form', array('form' => $form)) ?>
This is the executeIndex:
$this->aktion = AktionlimitPeer::getByName($this->getUser()->getAttribute('aktion'));
$aktionParam = new Aktion();
$aktionParam->setName($this->aktion->getName());
$this->form = new AktionlimitForm(array(), array("aktion" => $aktionParam));
The AktionLimitForm looks like this:
$aktionForm = new AktionForm($this->getOption('aktion'), array("limit" => true));
$this->embedForm('Aktion', $aktionForm);
$this->widgetSchema['neuerWert']= new sfWidgetFormInputText();
The embedded AktionForm has just one element (a dropdown-box which includes the unique names of the objects of „Aktion“):
$this->widgetSchema['name'] = new sfWidgetFormChoice(array('choices' => AktionPeer::getTypes()),array('onchange' => '???'));
Whenever the user chooses another „aktion“ in the dropdown-box I want to load the current object „aktion“ (referenced by the name) in executeIndex and show its values (Value 1-3) in indexSuccess.(When submitting it leads to another action.)
I need a function which calls executeIndex in the onChange-Event. I probably have to declare the function in the web/js-folder, is this right?. But how do I call the function from the form? And how do I call an action in a JavaScript-Function?
I hope you understood what I've written – today I have some difficulties to explain this problem in English :) Could anybody help?
Share Improve this question edited May 3, 2013 at 12:20 iamdto 1,37211 silver badges23 bronze badges asked May 3, 2013 at 9:30 alexalex 1432 silver badges15 bronze badges1 Answer
Reset to default 6First of all, consider upgrading to symfony 2.
Then, you don't need to configure this in the form type, if you decide to use jquery (nice javascript framework). with jquery you can bind events to elements very easy.
$(document).ready( function() {
$('#id_of_the_form_field').change(function() {
// to get the selected value
var selected = $(this).val()
// do your magic pony stuff
});
});
To call your php actions from javascript, you need to make a ajax request to related route.
本文标签:
版权声明:本文标题:Symfony: Using JavaScript in a onChange-event in a form and calling an action from the JS-Function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744306865a2599837.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论