Yii Framework Forum: Problem with .on('change.yii',...) and retrieving value - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Problem with .on('change.yii',...) and retrieving value

#1 User is offline   JFReyes 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 517
  • Joined: 28-October 09
  • Location:Puerto Rico

Posted 21 December 2017 - 06:14 PM

Hi all:

I have this code in a JS asset for a select element:
function contactedCaseInfo() {
    $("#contacted-cases_id").on("change.yii", function() {
        var casenum = $("#contacted-form-id").yiiActiveForm("find", "contacted-cases_id").value;
        alert("Case number is: " + casenum);
    });
}
contactedCaseInfo();


I can also do:
var casenum = $("contacted-cases_id").value;


with the same results.

Whenever the change is triggered I get either empty for a first time selection (doesn't matter what I select) or else the value of the previous selection after the first one when I keep selecting. It looks like the .on() event is firing too fast to allow the value of the select option to settle. Any ideas on how to handle this? Thanks for the help.

Regards,
José
0

#2 User is offline   JFReyes 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 517
  • Joined: 28-October 09
  • Location:Puerto Rico

Posted 22 December 2017 - 04:21 PM

Nevermind, I solved it; instead of
 var casenum = $("#contacted-form-id").yiiActiveForm("find", "contacted-cases_id").value;


it was as easy as
var casenum = $(this).val();


Still don't understand why yiiActiveForms('find',...) didn't work.

Cheers,
José
0

Share this topic:


Page 1 of 1
  • 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