New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add actions parameter to radio-widget #5026
Closed
Closed
Changes from 133 commits
Commits
Show all changes
134 commits
Select commit
Hold shift + click to select a range
090e812
add a new-line before the log text to increase readability of the tes…
pmario 5f35bab
make eslint, jslint happy
pmario 4d610fa
Merge remote-tracking branch 'jermolene/master'
pmario 4f68732
Merge remote-tracking branch 'jermolene/master'
pmario c0d4507
Merge remote-tracking branch 'jermolene/master'
pmario 19e9eff
Merge remote-tracking branch 'jermolene/master'
pmario 8f5b635
Merge remote-tracking branch 'jermolene/master'
pmario 15f79e1
Merge remote-tracking branch 'jermolene/master'
pmario 789e6fb
Merge remote-tracking branch 'jermolene/master'
pmario f39eaf1
Merge remote-tracking branch 'jermolene/master'
pmario b97cf82
Merge remote-tracking branch 'jermolene/master'
pmario c1448df
Merge remote-tracking branch 'jermolene/master'
pmario a30852a
it shouldn't be there
pmario b63b602
fremove this file from my PRs
pmario bc192f8
Merge remote-tracking branch 'jermolene/master'
pmario 611da36
Merge remote-tracking branch 'jermolene/master'
pmario 9f8d930
Merge remote-tracking branch 'jermolene/master'
pmario f8789d7
Merge remote-tracking branch 'jermolene/master'
pmario ae84acd
Merge remote-tracking branch 'jermolene/master'
pmario cc07cf8
Merge remote-tracking branch 'jermolene/master'
pmario 4fe0310
Merge remote-tracking branch 'origin/master'
pmario 31ce0cf
Merge remote-tracking branch 'jermolene/master'
pmario ea29fdb
Merge remote-tracking branch 'jermolene/master'
pmario 3c9b6f1
add a new-line before the log text to increase readability of the tes…
pmario bd0b9a3
make eslint, jslint happy
pmario 0589f60
it shouldn't be there
pmario 34866cb
fremove this file from my PRs
pmario 313a7ef
Merge remote-tracking branch 'origin/master'
pmario 7d92bd0
Merge remote-tracking branch 'jermolene/master'
pmario 83516c8
add a new-line before the log text to increase readability of the tes…
pmario 267b001
make eslint, jslint happy
pmario 01555e1
it shouldn't be there
pmario 1af3cb7
fremove this file from my PRs
pmario 422f862
add a new-line before the log text to increase readability of the tes…
pmario 4ee1de0
make eslint, jslint happy
pmario 5f51070
it shouldn't be there
pmario 925871e
fremove this file from my PRs
pmario 83b40e0
Merge remote-tracking branch 'jermolene/master'
pmario 32f8666
Merge remote-tracking branch 'origin/master'
pmario 48f51d0
Merge remote-tracking branch 'jermolene/master'
pmario 7738c4d
Merge remote-tracking branch 'origin/master'
pmario ee59fb4
add a new-line before the log text to increase readability of the tes…
pmario c1f3b08
make eslint, jslint happy
pmario faca4d7
it shouldn't be there
pmario 393447f
fremove this file from my PRs
pmario 2cca066
add a new-line before the log text to increase readability of the tes…
pmario 1ceb069
make eslint, jslint happy
pmario 3fd944f
it shouldn't be there
pmario d3881b2
fremove this file from my PRs
pmario bf5ace9
add a new-line before the log text to increase readability of the tes…
pmario 264090a
make eslint, jslint happy
pmario 0933fac
it shouldn't be there
pmario 7358345
fremove this file from my PRs
pmario 23f88d7
add a new-line before the log text to increase readability of the tes…
pmario 4a4f53a
make eslint, jslint happy
pmario e247e68
it shouldn't be there
pmario 7de28db
fremove this file from my PRs
pmario 03b697c
Merge remote-tracking branch 'origin/master'
pmario 1708b89
Merge remote-tracking branch 'origin/master' into master
pmario 80d6bb9
add a new-line before the log text to increase readability of the tes…
pmario c57a52f
make eslint, jslint happy
pmario f4c8fd1
it shouldn't be there
pmario f8fe8d5
fremove this file from my PRs
pmario bf7c65d
add a new-line before the log text to increase readability of the tes…
pmario d89471b
make eslint, jslint happy
pmario b503781
it shouldn't be there
pmario 90662c8
fremove this file from my PRs
pmario 2907799
add a new-line before the log text to increase readability of the tes…
pmario cdcb873
make eslint, jslint happy
pmario 145197a
it shouldn't be there
pmario d5c03e5
fremove this file from my PRs
pmario dbf96a9
add a new-line before the log text to increase readability of the tes…
pmario 00c0b7f
make eslint, jslint happy
pmario e0dd0d2
it shouldn't be there
pmario 784329a
fremove this file from my PRs
pmario 283c844
add a new-line before the log text to increase readability of the tes…
pmario e86bc01
make eslint, jslint happy
pmario 38fb557
it shouldn't be there
pmario 58a009a
fremove this file from my PRs
pmario e249760
add a new-line before the log text to increase readability of the tes…
pmario 2413d34
make eslint, jslint happy
pmario d37e21a
it shouldn't be there
pmario ae0e266
fremove this file from my PRs
pmario 6686fdd
add a new-line before the log text to increase readability of the tes…
pmario 29be731
make eslint, jslint happy
pmario 6259d87
it shouldn't be there
pmario 9af4fc5
fremove this file from my PRs
pmario 14fd2f3
add a new-line before the log text to increase readability of the tes…
pmario 0de7341
make eslint, jslint happy
pmario 5a8cbc1
it shouldn't be there
pmario 0149239
fremove this file from my PRs
pmario 067a76e
Don't override browser selection colours by default
Jermolene 95b99ed
add a new-line before the log text to increase readability of the tes…
pmario 4209280
make eslint, jslint happy
pmario 51525a1
it shouldn't be there
pmario 36ab8a8
fremove this file from my PRs
pmario 0d9c15d
add a new-line before the log text to increase readability of the tes…
pmario c37cf0c
make eslint, jslint happy
pmario 07d8a39
it shouldn't be there
pmario 672868e
fremove this file from my PRs
pmario 00b2c14
add a new-line before the log text to increase readability of the tes…
pmario 4f95321
make eslint, jslint happy
pmario 42167b4
it shouldn't be there
pmario b25ff28
fremove this file from my PRs
pmario 7cb6a69
add a new-line before the log text to increase readability of the tes…
pmario 5e67097
make eslint, jslint happy
pmario d426385
it shouldn't be there
pmario bf55dbe
fremove this file from my PRs
pmario e77cef9
add a new-line before the log text to increase readability of the tes…
pmario 3c10009
make eslint, jslint happy
pmario fa72a58
it shouldn't be there
pmario 8436970
fremove this file from my PRs
pmario f84a5f5
add a new-line before the log text to increase readability of the tes…
pmario f2e5744
make eslint, jslint happy
pmario a223738
it shouldn't be there
pmario 8a15f34
fremove this file from my PRs
pmario 4624788
add a new-line before the log text to increase readability of the tes…
pmario 46fd2a5
make eslint, jslint happy
pmario 99a6bf3
it shouldn't be there
pmario 958fa42
fremove this file from my PRs
pmario 6c3bff4
Merge branch 'master' of https://github.com/Jermolene/TiddlyWiki5 int…
pmario b98e1ca
Merge branch 'master' of github.com:pmario/TiddlyWiki5 into master
pmario dcf722b
Merge branch 'master' of https://github.com/Jermolene/TiddlyWiki5 int…
pmario 4ac2495
Merge branch 'master' of https://github.com/Jermolene/TiddlyWiki5 int…
pmario 86bf726
Merge branch 'master' of https://github.com/Jermolene/TiddlyWiki5 int…
pmario c9a65f3
Merge branch 'master' of https://github.com/Jermolene/TiddlyWiki5 int…
pmario 9de7442
WIP initial test radio actions
pmario 3968ac2
WIP first try to add actions to radio buttons
pmario 1dbe8f7
WIP add tiddler and field variables
pmario bb93ddc
WIP code refactoring to make it consistent
pmario 50ffeed
add parameter prefix "attr-" and update refresh handling
pmario 89ad523
add `actionValue` to the action variables
pmario 65cbba3
if this.radioTitle is changed, it nees a refreshSelf(), otherwise the…
pmario a00fc21
simplify widget refres code
pmario File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ Set a field or index at a given tiddler via radio buttons | |
"use strict"; | ||
|
||
var Widget = require("$:/core/modules/widgets/widget.js").widget; | ||
|
||
var RadioWidget = function(parseTreeNode,options) { | ||
this.initialise(parseTreeNode,options); | ||
}; | ||
|
@@ -37,8 +36,8 @@ RadioWidget.prototype.render = function(parent,nextSibling) { | |
// Create our elements | ||
this.labelDomNode = this.document.createElement("label"); | ||
this.labelDomNode.setAttribute("class", | ||
"tc-radio " + this.radioClass + (isChecked ? " tc-radio-selected" : "") | ||
); | ||
"tc-radio " + this.radioClass + (isChecked ? " tc-radio-selected" : "") | ||
); | ||
this.inputDomNode = this.document.createElement("input"); | ||
this.inputDomNode.setAttribute("type","radio"); | ||
if(isChecked) { | ||
|
@@ -83,9 +82,24 @@ RadioWidget.prototype.setValue = function() { | |
}; | ||
|
||
RadioWidget.prototype.handleChangeEvent = function(event) { | ||
var variables = Object.create(null); | ||
if(this.inputDomNode.checked) { | ||
this.setValue(); | ||
} | ||
// Trigger actions. Use variables = {key:value, key:value ...} | ||
if(this.radioActions) { | ||
$tw.utils.each(this.attributes,function(val,key) { | ||
if(key.charAt(0) !== "$") { | ||
variables["attr-" + key] = val; | ||
} | ||
}); | ||
// "tiddler" and/or "field" parameter may be missing in the widget call. See .execute() below | ||
variables = $tw.utils.extend(variables, {"actionValue": this.radioValue, | ||
"attr-tiddler": this.radioTitle, | ||
"attr-field": this.radioField | ||
}); | ||
this.invokeActionString(this.radioActions,this,event,variables); | ||
} | ||
}; | ||
|
||
/* | ||
|
@@ -99,6 +113,7 @@ RadioWidget.prototype.execute = function() { | |
this.radioValue = this.getAttribute("value"); | ||
this.radioClass = this.getAttribute("class",""); | ||
this.isDisabled = this.getAttribute("disabled","no"); | ||
this.radioActions = this.getAttribute("actions",""); | ||
// Make the child widgets | ||
this.makeChildWidgets(); | ||
}; | ||
|
@@ -108,16 +123,15 @@ Selectively refreshes the widget if needed. Returns true if the widget or any of | |
*/ | ||
RadioWidget.prototype.refresh = function(changedTiddlers) { | ||
var changedAttributes = this.computeAttributes(); | ||
if(changedAttributes.tiddler || changedAttributes.field || changedAttributes.index || changedAttributes.value || changedAttributes["class"] || changedAttributes.disabled) { | ||
if($tw.utils.count(changedAttributes) > 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps:
|
||
this.refreshSelf(); | ||
return true; | ||
} else { | ||
var refreshed = false; | ||
if(changedTiddlers[this.radioTitle]) { | ||
this.inputDomNode.checked = this.getValue() === this.radioValue; | ||
refreshed = true; | ||
this.refreshSelf(); | ||
return true; | ||
} | ||
return this.refreshChildren(changedTiddlers) || refreshed; | ||
return this.refreshChildren(changedTiddlers); | ||
} | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -554,6 +554,7 @@ Widget.prototype.invokeActions = function(triggeringWidget,event) { | |
|
||
/* | ||
Invoke the action widgets defined in a string | ||
variables needs to be an object eg: {key:value, key:value} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did add 1 line comment here, since it would have saved me some time. |
||
*/ | ||
Widget.prototype.invokeActionString = function(actions,triggeringWidget,event,variables) { | ||
actions = actions || ""; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Jermolene @pmario So is the intention that all attributes starting with
$
are a reserved name space for future attributes that we might want to add to the widget? By allowing users to use arbitrary attribute names, in effect every attribute name becomes a reserved one, as it could clash with widget attributes that we introduce in the future.At the moment it is just
action-widgets
that have attributes starting with$
. This is confusing enough as it is but at least users can remember the rule that non-action widget attribute names do not start with$
.It would be quite confusing if suddenly any widget could have attribute names that may or not start with
$
. Especially if the widget previously has many attributes with no $ prefix and then suddenly has one new one introduced with a$
prefix.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would you suggest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could imagine, that "user_attributes" start with an underscore. eg:
_user-attribute
andreserved-for-core
and$reserved-for-core
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or:
__attribute
with 2 underscoresThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pmario I don't have an obvious solution that I particularly love.
However I think it is important that:
a) we try to avoid the potential confusion with attribute names if we can.
b) if we are going to proceed with this change, it needs to be a conscious decision where we consider the benefit of declaring variables in this manner vs the cost of creating usability issues and decide if this change is worthwhile.
In terms of other implementation approaches I considered requiring all user declared attributes to have a specific prefix, like
var-
. The problem is that while that makes it easier to identify user attributes, it makes it trickier to loop through the attributes and identify which is a widget "native" attribute since they have no specific prefix.Every widget could have a list of attributes that get turned into variables, plus any user ones with a given prefix.
So in pseudo-code:
The other option we could consider is not to enforce a prefix for user attributes in the code, but rather make it a part of documentation and best practice. Explaining that using user attributes without a reserved prefix like "var-" could cause upgrade problems in the future. The problem with this approach is that I suspect most users will ignore it, and we will still have support issues when attribute names do clash in the future.
Does any of this perhaps inspire any ideas for you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pmario I didn't get to see your subsequent comments while typing. But yes, a prefix for user declared attributes would solve the problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sometimes using a similar approach in my plugins, to make attribute code "loopable", if there are many of them, or if I'm not sure about the names. So it's easy to change the names, because I only need to change the innitial array.
So IMO @Jermolene should have a closer look.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Jermolene to try and summarize for you:
allowing any arbitrary name for attributes assigned by users to create variables, means that every attribute name is potentially a reserved name when/if we want to add more widget attributes in the future
The code in this PR reserves the
$
prefix namespace for attributes. So presumably future widget attributes would have to start with$
. This is a usability concern, as outside of action widgets users can reliably expect widget attributes not to start with$
. Imagine if theButton
widget which has been around for a long time and has many attributes, suddenly has a new attribute that starts with$
.One suggestion to mitigate this is, to require user assigned widget attributes to have a specific prefix, such as
_
or evenattr-
(in which case the name of the custom attribute and the variable arising from it could be the same).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The behaviour here is so novel compared to other widgets that I favour a big obvious prefix on the user defined attributes that are to be passed through to the action string. I think
var-xxx
makes some sense for both the attribute names and variable names because it makes it clearer that this is a mini version of the<$vars>
widget...