Re: Event observer not working in version prototype 1.7 but works fine in 1.5

345 views
Skip to first unread message

Victor

unread,
Aug 9, 2012, 5:36:41 AM8/9/12
to prototype-s...@googlegroups.com
Form.YooEventObserver = Class.create({Abstract.EventObserver, {
  minQueryLength: 3,
  
  getValue: function() {
    // return YAHOO.util.Connect.setForm(this.element);
    //return Form.serialize(this.element);
  },

  // ... other methods
});

Imdad Ali Khan

unread,
Aug 9, 2012, 7:14:30 AM8/9/12
to prototype-s...@googlegroups.com
Sorry Victor it did not work, i had below in js file..

Form.YooEventObserver = Class.create(Abstract.EventObserver, {
  minQueryLength: 3,
  
  getValue: function() {
    // return YAHOO.util.Connect.setForm(this.element);
    //return Form.serialize(this.element);
  },
  
  registerFormCallbacks: function() {
    Event.observe(this.element, 'reset', this.onFormResetEvent.bind(this));
    Form.getElements(this.element).each(this.registerCallback.bind(this));
  },
  
  formResetAction: function() {
    var value = this.getValue();
    // calling again so that serialization is correct
    value = this.getValue();
    this.lastValue = value;
    this.lastCallbackValue = value;
    this.callback(this, value + '&reset=true');
  },
  
  onFormResetEvent: function(){
    // Delaying so that serialization is correct
    setTimeout(this.formResetAction.bind(this), 10)
    //this.formResetAction.bind(this)
  },
  
  onElementEvent: function() {
    var value = this.getValue();
    if (this.lastValue != value) {
      this.callback(this.element, value);
      this.lastValue = value;
    }
  },
  
  onTextElementEvent: function(el) {
    var value = this.getValue();
    if (this.lastValue != value) {
      if ( 
        ((el.getValue() || '').length + 1 > this.minQueryLength  || (el.getValue() || '').length === 0 ) && 
        value != this.lastCallbackValue
      ){
        this.callback(this.element, value);
        this.lastCallbackValue = value;
      }
      this.lastValue = value;
    };
  },
  
  registerCallback: function(element) {
    this.lastCallbackValue = this.getValue();
    if (element.type) {
      switch (element.type.toLowerCase()) {
        case 'checkbox':
        case 'radio':
          Event.observe(element, 'click', this.onElementEvent.bind(this));
          Event.observe(element, 'change', this.onElementEvent.bind(this));
          break;
        case 'text':
        case 'textbox':
        case 'textarea':
          new Form.Element.Observer(element, 0.22, this.onTextElementEvent.bind(this, element));
          break;
        case 'hidden':
          new Form.Element.Observer(element, 0.10, this.onElementEvent.bind(this));
          break;
        default:
          Event.observe(element, 'change', this.onElementEvent.bind(this));
          break;
      }
    }
  }
  
});

and i got this error while refreshing chrome window.

  1. Uncaught Error: ExecJS::ProgramError: Unexpected token: operator (*) (line: 9987, col: 4, pos: 392034) Error at new JS_Parse_Error (<eval>:1720:22) at js_error (<eval>:1728:15) at croak (<eval>:2189:17) at token_error (<eval>:2196:17) at unexpected (<eval>:2202:17) at <eval>:2580:17 at maybe_unary (<eval>:2665:27) at expr_ops (<eval>:2692:32) at maybe_conditional (<eval>:2696:28) at maybe_assign (<eval>:2720:28) (in /Users/mac/yoopedia/dev/app/assets/javascripts/preload.js) /assets/preload.js:1
  1. Uncaught ReferenceError: Form is not defined yoo:361
  1. Uncaught ReferenceError: Form is not defined yoo:549
  1. Uncaught ReferenceError: gY is not defined yoo:860
  1. Uncaught ReferenceError: YAHOO is not defined postload.js:7
  1. Uncaught ReferenceError: YAHOO is not defined yoo:1019
  1. Uncaught ReferenceError: YAHOO is not defined

Victor

unread,
Aug 10, 2012, 3:48:09 AM8/10/12
to prototype-s...@googlegroups.com

  1. Uncaught ReferenceError: Form is not defined yoo:361
  1. Uncaught ReferenceError: Form is not defined yoo:549
  1. Uncaught ReferenceError: gY is not defined yoo:860
  1. Uncaught ReferenceError: YAHOO is not defined postload.js:7
  1. Uncaught ReferenceError: YAHOO is not defined yoo:1019
  1. Uncaught ReferenceError: YAHOO is not defined

Is Prototype and Yahoo properly loaded before your script?

Imdad Ali Khan

unread,
Aug 10, 2012, 11:19:38 AM8/10/12
to prototype-s...@googlegroups.com
Yes these are loaded properly, here are the include order of these file....

//= require prototype
//= require prototype_ujs
//= require effects
//= require dragdrop
//= require controls
//= require  ./yui/utilities
//= require ./yui/tabview-min.js
//= require  ./main/base
//= require  ./main/mainpage_preload
//= require  ./main/userhome

The function defined are in mainpage_preload.js

Victor

unread,
Aug 13, 2012, 7:55:32 AM8/13/12
to prototype-s...@googlegroups.com
Yes these are loaded properly, here are the include order of these file....

Can you verify this in your browser? Also, there may be syntax error in some of javascript files. Try to comment them one by one until error message (Uncaught Error: ExecJS::ProgramError: Unexpected token: operator (*) (line: 9987, col: 4, pos: 392034)) disappears.
Reply all
Reply to author
Forward
0 new messages