-
-
Notifications
You must be signed in to change notification settings - Fork 78.5k
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
Manipulator: Add JSON parse support #35077
Conversation
1fc32ce
to
f92dea6
Compare
f92dea6
to
0e3e985
Compare
0e3e985
to
b99f677
Compare
0bd791a
to
a7aa0cc
Compare
ff02c45
to
18886a3
Compare
b7c0ff2
to
d0795b2
Compare
d0795b2
to
3d44f5a
Compare
7eef37a
to
839e385
Compare
c5bbfbd
to
e175161
Compare
fbd609c
to
6259a88
Compare
6259a88
to
0bc10c4
Compare
@@ -44,7 +52,7 @@ const Manipulator = { | |||
} | |||
|
|||
const attributes = {} | |||
const bsKeys = Object.keys(element.dataset).filter(key => key.startsWith('bs')) | |||
const bsKeys = Object.keys(element.dataset).filter(key => key.startsWith('bs') && !key.startsWith('bsConfig')) | |||
|
|||
for (const key of bsKeys) { | |||
let pureKey = key.replace(/^bs/, '') |
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.
@GeoSot shouldn't this remove bsConfig
too?
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.
yes, I want to filter bsConfig
out of given results . My purpose is to can be accessed only on purpose and not by massive get
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 not sure I understand. Right now, bsConfig
is not normalized, right? Shouldn't it be normalized here?
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.
here (getDataAttributes
) is omitted, on purpose (of mass getting).
We may need to think of normalization only in config.js usage, but I didn't do it, as the normalization of the json string should have be done already from the developer. We after all validate the final object.
(Check the tests please too. I think they cover your thoughts on line 80)
dd77795
to
a267616
Compare
Hi, I'm new to this...why did the test fail due to the disconnected test? |
I must remind you that in html the values of an attribute are enclosed in double quotes: the solution would be something like this:
|
If anyone could enlighten me too, I would be much happier. 😕 |
…he `data-bs-config` attribute. Experimental ! ! ! The `bs-config` attribute will be reserved and omitted during `getDataAttributes` parsing With this commit, every component, will create its config obj, using * Defaults * data-bs-config * rest data attributes * configuration object given during instance initialization
a267616
to
c1b1faa
Compare
It's ok by me. XhmikosR may have the last word |
What if you want your string that looks like JSON to be treated like a string? Edit: const content = popoverTriggerEl.getAttribute('data-bs-content');
if (content.startsWith('{')) {
popoverTriggerEl.setAttribute('data-bs-content', content.replace('{', '{'));
} |
For example, taking from the manual https://getbootstrap.com/docs/5.2/components/popovers/#live-demo: <button type="button" class="btn btn-lg btn-danger" data-bs-toggle="popover" data-bs-title="Popover title" data-bs-content='{"id":1234, "text":"This has worked for over a decade."}'>Click to toggle popover</button> |
A proposal trying to solve the JSON data-attributes parsing issue.
Merging this PR, components will be able to parse JSON string values from element data attributes as configuration values.
Edit: As an experimental add on, component elements can have a
data-bs-config
attribute that can house all the component config as JSON string. In case an element hasdata-bs-config='{"foo":123}'
anddata-bs-foo="456"
attributes, finalfoo
value will be456
, as the separate data attributes will override values given ondata-bs-config
So the final config for each components will be a result of:
I would appreciate any thoughts or doubts on it
Refs #34259, refs #34321, refs #35880
closes #34465
TODO: