Skip to content

Commit 35c5207

Browse files
authored
Recipe config 78207 (#55)
* Add copyPlaceholder option to CUI.Input New boolean option that shows a button inside the input (on hover) to apply the placeholder value as the actual input value. The button is only visible when there is a placeholder and the input is empty. Uses storeValue to support NumberInput correctly. Also propagates the option through MultiInput to MultiInputInput for multi-language field support. See #78207
1 parent b165093 commit 35c5207

6 files changed

Lines changed: 283 additions & 3 deletions

File tree

public/cui.js

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48485,6 +48485,10 @@ CUI.Input = (function(superClass) {
4848548485
check: function(v) {
4848648486
return v instanceof CUI.DOMElement;
4848748487
}
48488+
},
48489+
copyPlaceholder: {
48490+
"default": false,
48491+
check: Boolean
4848848492
}
4848948493
});
4849048494
};
@@ -48573,7 +48577,8 @@ CUI.Input = (function(superClass) {
4857348577
if (typeof this.__resizeForPlaceholder === "function") {
4857448578
this.__resizeForPlaceholder();
4857548579
}
48576-
return this.setContentSize();
48580+
this.setContentSize();
48581+
return this.__updateCopyPlaceholderButton();
4857748582
};
4857848583

4857948584
Input.prototype.getPlaceholder = function() {
@@ -49391,6 +49396,9 @@ CUI.Input = (function(superClass) {
4939149396
CUI.dom.addClass(this._leftControlElement, 'cui-input-control-element');
4939249397
this.prepend(this._leftControlElement, this.getTemplateKeyForRender());
4939349398
}
49399+
if (this._copyPlaceholder) {
49400+
this.__initCopyPlaceholderButton();
49401+
}
4939449402
ref = ["empty", "invalid", "valid"];
4939549403
for (j = 0, len1 = ref.length; j < len1; j++) {
4939649404
k = ref[j];
@@ -49512,6 +49520,7 @@ CUI.Input = (function(superClass) {
4951249520
this.__input.value = value;
4951349521
}
4951449522
this.checkInput();
49523+
this.__updateCopyPlaceholderButton();
4951549524
return this;
4951649525
};
4951749526

@@ -49785,6 +49794,56 @@ CUI.Input = (function(superClass) {
4978549794
return this;
4978649795
};
4978749796

49797+
Input.prototype.__initCopyPlaceholderButton = function() {
49798+
this.__copyPlaceholderBtn = new CUI.Button({
49799+
icon: "fa-level-down",
49800+
"class": "cui-input-copy-placeholder-button",
49801+
tooltip: {
49802+
text: "Apply"
49803+
},
49804+
onClick: (function(_this) {
49805+
return function() {
49806+
var placeholder;
49807+
placeholder = _this.getPlaceholder();
49808+
if (CUI.util.isEmpty(placeholder)) {
49809+
return;
49810+
}
49811+
_this.__input.value = placeholder;
49812+
_this.storeValue(placeholder);
49813+
_this.checkInput();
49814+
_this.__updateCopyPlaceholderButton();
49815+
};
49816+
})(this)
49817+
});
49818+
this.append(this.__copyPlaceholderBtn, this.getTemplateKeyForRender());
49819+
this.__updateCopyPlaceholderButton();
49820+
CUI.Events.listen({
49821+
node: this.__input,
49822+
type: "input",
49823+
instance: this,
49824+
call: (function(_this) {
49825+
return function() {
49826+
return _this.__updateCopyPlaceholderButton();
49827+
};
49828+
})(this)
49829+
});
49830+
};
49831+
49832+
Input.prototype.__updateCopyPlaceholderButton = function() {
49833+
var hasPlaceholder, hasValue, placeholder;
49834+
if (!this.__copyPlaceholderBtn) {
49835+
return;
49836+
}
49837+
placeholder = this.getPlaceholder();
49838+
hasPlaceholder = !CUI.util.isEmpty(placeholder);
49839+
hasValue = this.hasUserInput();
49840+
if (hasPlaceholder && !hasValue) {
49841+
CUI.dom.showElement(this.__copyPlaceholderBtn);
49842+
} else {
49843+
CUI.dom.hideElement(this.__copyPlaceholderBtn);
49844+
}
49845+
};
49846+
4978849847
Input.prototype.destroy = function() {
4978949848
this.__removeShadowInput();
4979049849
return Input.__super__.destroy.call(this);
@@ -58307,6 +58366,10 @@ CUI.MultiInput = (function(superClass) {
5830758366
user_selectable: {
5830858367
"default": false,
5830958368
check: Boolean
58369+
},
58370+
copyPlaceholder: {
58371+
"default": false,
58372+
check: Boolean
5831058373
}
5831158374
});
5831258375
};
@@ -58518,7 +58581,7 @@ CUI.MultiInput = (function(superClass) {
5851858581
};
5851958582

5852058583
MultiInput.prototype.__initInputs = function() {
58521-
var fn, i, idx, input, input_opts, key, len, ref, ref1, ref2;
58584+
var fn, i, idx, input, input_opts, key, len, ref, ref1, ref2, ref3;
5852258585
if (this.__inputs) {
5852358586
return;
5852458587
}
@@ -58628,6 +58691,7 @@ CUI.MultiInput = (function(superClass) {
5862858691
undo_support: false,
5862958692
content_size: this._content_size,
5863058693
placeholder: ((ref1 = this._placeholder) != null ? ref1[key.name] : void 0) || ((ref2 = this._placeholder) != null ? ref2["default"] : void 0),
58694+
copyPlaceholder: this._copyPlaceholder && !CUI.util.isEmpty((ref3 = this._placeholder) != null ? ref3[key.name] : void 0),
5863158695
onDataInit: (function(_this) {
5863258696
return function(field, data) {
5863358697
if (_this.__user_selectable && CUI.util.isEmpty(data[field.getName()])) {

public/cui.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/cui_fylr.css

Lines changed: 97 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/elements/Input/Input.coffee

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ class CUI.Input extends CUI.DataFieldInput
155155
check: (v) -> v instanceof CUI.DOMElement or CUI.util.isFunction(v)
156156
leftControlElement:
157157
check: (v) -> v instanceof CUI.DOMElement
158+
copyPlaceholder:
159+
default: false
160+
check: Boolean
158161

159162
readOpts: ->
160163

@@ -225,6 +228,7 @@ class CUI.Input extends CUI.DataFieldInput
225228
CUI.dom.setAttribute(@__input, "placeholder", placeholder)
226229
@__resizeForPlaceholder?()
227230
@setContentSize()
231+
@__updateCopyPlaceholderButton()
228232

229233
getPlaceholder: ->
230234
if @__dynamicPlaceholder
@@ -989,6 +993,9 @@ class CUI.Input extends CUI.DataFieldInput
989993
CUI.dom.addClass(@_leftControlElement, 'cui-input-control-element')
990994
@prepend(@_leftControlElement, @getTemplateKeyForRender())
991995

996+
if @_copyPlaceholder
997+
@__initCopyPlaceholderButton()
998+
992999
# @append(@getChangedMarker(), @getTemplateKeyForRender())
9931000

9941001
for k in ["empty", "invalid", "valid"]
@@ -1080,6 +1087,7 @@ class CUI.Input extends CUI.DataFieldInput
10801087
# prevent focus loss if value is the same
10811088
@__input.value = value
10821089
@checkInput()
1090+
@__updateCopyPlaceholderButton()
10831091
@
10841092

10851093
getValueForDisplay: ->
@@ -1331,6 +1339,47 @@ class CUI.Input extends CUI.DataFieldInput
13311339
#console.debug "moveCursor new range", @getRangeFromCursor()
13321340
@
13331341

1342+
__initCopyPlaceholderButton: ->
1343+
@__copyPlaceholderBtn = new CUI.Button
1344+
icon: "fa-level-down"
1345+
class: "cui-input-copy-placeholder-button"
1346+
tooltip: text: "Apply"
1347+
onClick: =>
1348+
placeholder = @getPlaceholder()
1349+
if CUI.util.isEmpty(placeholder)
1350+
return
1351+
@__input.value = placeholder
1352+
@storeValue(placeholder)
1353+
@checkInput()
1354+
@__updateCopyPlaceholderButton()
1355+
return
1356+
1357+
@append(@__copyPlaceholderBtn, @getTemplateKeyForRender())
1358+
@__updateCopyPlaceholderButton()
1359+
1360+
CUI.Events.listen
1361+
node: @__input
1362+
type: "input"
1363+
instance: @
1364+
call: =>
1365+
@__updateCopyPlaceholderButton()
1366+
1367+
return
1368+
1369+
__updateCopyPlaceholderButton: ->
1370+
if not @__copyPlaceholderBtn
1371+
return
1372+
1373+
placeholder = @getPlaceholder()
1374+
hasPlaceholder = not CUI.util.isEmpty(placeholder)
1375+
hasValue = @hasUserInput()
1376+
1377+
if hasPlaceholder and not hasValue
1378+
CUI.dom.showElement(@__copyPlaceholderBtn)
1379+
else
1380+
CUI.dom.hideElement(@__copyPlaceholderBtn)
1381+
return
1382+
13341383
destroy: ->
13351384
@__removeShadowInput()
13361385
super()

src/elements/MultiInput/MultiInput.coffee

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ class CUI.MultiInput extends CUI.DataFieldInput
4141
user_selectable:
4242
default: false
4343
check: Boolean
44+
copyPlaceholder:
45+
default: false
46+
check: Boolean
4447

4548
readOpts: ->
4649
super()
@@ -212,6 +215,7 @@ class CUI.MultiInput extends CUI.DataFieldInput
212215
undo_support: false
213216
content_size: @_content_size
214217
placeholder: @_placeholder?[key.name] or @_placeholder?["default"]
218+
copyPlaceholder: @_copyPlaceholder and not CUI.util.isEmpty(@_placeholder?[key.name])
215219
onDataInit: (field, data) =>
216220
if @__user_selectable and CUI.util.isEmpty(data[field.getName()])
217221
field.hide()

0 commit comments

Comments
 (0)