Skip to content

Commit ac2563c

Browse files
committed
Merge commit dev into dev-bl/edit-edge-lock
* commit '2554384120687f63033afdb1c73493cb08a8a644': dev-bl/select-node-onblur: When AutoComplete field loses focus, if the current value matches a node, select it.
2 parents 5ee1013 + 2554384 commit ac2563c

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

build/app/view/netcreate/components/AutoComplete.jsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ class AutoComplete extends UNISYS.Component {
169169
this.onSuggestionSelected = this.onSuggestionSelected.bind(this);
170170
this.onSuggestionHighlighted = this.onSuggestionHighlighted.bind(this);
171171
this.shouldRenderSuggestions = this.shouldRenderSuggestions.bind(this);
172+
this.onBlur = this.onBlur.bind(this);
172173

173174
// NOTE: do this AFTER you have used bind() on the class method
174175
// otherwise the call will fail due to missing 'this' context
@@ -330,6 +331,13 @@ class AutoComplete extends UNISYS.Component {
330331
/*/ shouldRenderSuggestions (value) {
331332
return this.state.mode===MODE_ACTIVE;
332333
}
334+
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
335+
/*/ The AutoComplete field has lost focus.
336+
Check to see if it references a valid node, if so, select it
337+
/*/ onBlur (value) {
338+
// User selected an existing node in the suggestion list
339+
this.AppCall('SOURCE_SEARCH_AND_SELECT', { searchString: this.state.value } );
340+
}
333341

334342
/// REACT LIFECYCLE /////////////////////////////////////////////////////////
335343
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -358,7 +366,8 @@ class AutoComplete extends UNISYS.Component {
358366
const inputProps = {
359367
placeholder : "Type node name...",
360368
value : value,
361-
onChange : this.onInputChange
369+
onChange : this.onInputChange,
370+
onBlur : this.onBlur
362371
};
363372
let jsx;
364373

build/app/view/netcreate/nc-logic.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,8 @@ MOD.Hook("INITIALIZE", () => {
364364
SEE ALSO: AutoComplete.onSuggestionSelected() and
365365
D3SimpleNetGraph._UpdateGraph click handler
366366
/*/
367-
UDATA.HandleMessage("SOURCE_SELECT", function(data) {
367+
UDATA.HandleMessage("SOURCE_SELECT", m_sourceSelect);
368+
function m_sourceSelect (data) {
368369
if (DBG) console.log(PR, "SOURCE_SELECT got data", data);
369370

370371
let { nodeLabels = [], nodeIDs = [] } = data;
@@ -413,7 +414,7 @@ MOD.Hook("INITIALIZE", () => {
413414

414415
// Set the SELECTION state so that listeners such as NodeSelectors update themselves
415416
UDATA.SetAppState("SELECTION", newState);
416-
});
417+
}
417418

418419
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - inside hook
419420
/*/ SOURCE_SEARCH sets the current matching term as entered in an
@@ -432,6 +433,20 @@ MOD.Hook("INITIALIZE", () => {
432433
UDATA.SetAppState("SEARCH", newState);
433434
});
434435

436+
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - inside hook
437+
/*/ SOURCE_SEARCH_AND_SELECT first searches for an exact mathcing node
438+
and if found, selects it.
439+
This is called by AutoComplete onBlur in case we need to make an
440+
implicit selection.
441+
/*/
442+
UDATA.HandleMessage("SOURCE_SEARCH_AND_SELECT", function (data) {
443+
let { searchString } = data;
444+
let node = m_FindMatchingNodesByLabel(searchString).shift();
445+
if (node && (node.label === searchString)) {
446+
m_sourceSelect({ nodeIDs: [node.id] });
447+
}
448+
});
449+
435450
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - inside hook
436451
/*/ SOURCE_HILITE updates the currently rolled-over node name in a list of
437452
selections. The hilite can be selected via either the label or

0 commit comments

Comments
 (0)