Should have a way to tell the picker to get its initial value from a DOM element of the page it's on

Bug #482235 reported by Guilherme Salgado
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
LAZR Javascript Library
Fix Released
Undecided
Guilherme Salgado
Launchpad itself
Fix Released
Undecided
Guilherme Salgado

Bug Description

Sometimes the picker is activated by clicking on a link besides a text entry, and in such cases I usually start typing some text in the entry but then I realize I don't know the exact name/id of the thing I'm looking for, so I click on 'Choose...' to search for that thing. When I do that, the picker pops up and I have to type everything again because the picker doesn't take its initial value from the text entry besides it.

If there was a way to tell the picker to take its initial value from a DOM element of the page it's on, this could easily be done with no extra effort from the callsites.

Related branches

Changed in lazr-js:
assignee: nobody → Guilherme Salgado (salgado)
status: New → Triaged
Changed in lazr-js:
status: Triaged → In Progress
Revision history for this message
Guilherme Salgado (salgado) wrote :

My initial idea was to add an optional 'get_initial_value_from' attribute to the Picker so that callsites would be able to specify the DOM element from where the Picker would get the initial value for the search input.

However, Maris didn't like that idea because he thinks that'd make lazr-js too tied to LP's implementation (as the DOM node would have to provide a 'value' attribute), so he suggested adding this to an Y.lp.Picker, to be used in LP instead of the raw Picker.

Revision history for this message
Guilherme Salgado (salgado) wrote :

The others that were present at the lazr-js sprint in Dallas thought it'd be better to add the 'get_initial_value_from' attribute to the picker rather than adding it to a custom LP picker as that's a feature that's likely to benefit others.

Revision history for this message
Māris Fogels (mars) wrote :

Instead of a 'get_initial_value' attribute, I suggest calling the attribute simply 'initial_value'. The user sets it in the constructor.

To support your case, I suggest it support the user setting the value as a function. If initial_value is a function, then getting it will return that function's value.

// Support setting the initial value as a static text string
new Y.Picker({
  initial_value: 'foobar',
  input: 'input#baz'
});

// Support computing the initial value using a function
new Y.Picker({
  initial_value: function(input) {
    // Grabs the initial value from the DOM. The input node is passed in as a parameter to make things easier for the user.
    return input.get('value');
  },
  input: 'input#baz'
});

Revision history for this message
Guilherme Salgado (salgado) wrote : Re: [Bug 482235] Re: Should have a way to tell the picker to get its initial value from a DOM element of the page it's on

On Thu, 2009-12-10 at 13:21 +0000, Māris Fogels wrote:
> Instead of a 'get_initial_value' attribute, I suggest calling the
> attribute simply 'initial_value'. The user sets it in the constructor.
>
> To support your case, I suggest it support the user setting the value as
> a function. If initial_value is a function, then getting it will return
> that function's value.

The problem with this solution is that I then need to duplicate this
function in all callsites that make use of the feature, which is not
nice.

Bjorn suggested a different approach, which is simpler to use and yet
generic enough[1]. What do you think of that? Maybe we should move
this discussion to the merge proposal?

[1] https://code.edge.launchpad.net/~salgado/lazr-js/bug-482235/+merge/15940

Changed in lazr-js:
status: In Progress → Fix Committed
Changed in launchpad-foundations:
assignee: nobody → Guilherme Salgado (salgado)
status: New → In Progress
Changed in launchpad-foundations:
status: In Progress → Fix Committed
Changed in lazr-js:
status: Fix Committed → Fix Released
Changed in launchpad-foundations:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.