开发者

KRL - How do you get the value of a watched field?

开发者 https://www.devze.com 2023-02-02 11:03 出处:网络
I am watching a field on a page with a change. watch(\"#searchbox\",\"change\"); How do you get the new value of the field in the rule that fires after it changes?

I am watching a field on a page with a change.

watch("#searchbox","change");

How do you get the new value of the field in the rule that fires after it changes?

I have a rule like this

rule get_update is active {
 select when web change "#searchbox"
  ....
}
开发者_JS百科

I cannot find out how to get the new value. I cannot use watch it with a submit.

Thanks


I am going to guess what I think you are trying to do:

You have an input on a page and when a user types in the input, you want to be able to raise an event and get the new value from the input that the user was typing into so you can react to what ever it is that they typed in.

Based on the assumptions I have made:

The watch action is not what you really want to use because it only raises an event on the action that it is watching and doesn't send any other data along with the event. You will want to write some of your own custom JavaScript to

  • watch for the user typing
  • get the new value from the input
  • raise web event with the new value as a parameter

Here is some sample code taken from http://kynetxappaday.wordpress.com/2010/12/16/day-8-raise-web-events-from-javascript/ that illustrates raising a web event with a parameter in JavaScript

ruleset a60x488 {
  meta {
    name "raising-custom-web-events"
    description <<
      raising-custom-web-events
    >>
    author "Mike Grace"
    logging on
  }

  rule run_on_a_pageview {
    select when pageview ".*"
    {
      notify("Hello","I ran on a pageview") with sticky = true;
      emit <|
        app = KOBJ.get_application("a60x488");
        app.raise_event("custom_event_just_for_me", {"answer":42});
      |>;
    }
  }

  rule respond_to_custom_event_raised_from_emitted_js {
    select when web custom_event_just_for_me
    pre {
      answer = event:param("answer");
    }
    {
      notify("What is the answer?",answer) with sticky = true;
    }
  }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消