-
Notifications
You must be signed in to change notification settings - Fork 531
V3: dynamic html attributes #415
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
V3: dynamic html attributes #415
Conversation
…upport for other named sets) attributes to elements to support dynamic attributes (such as `title="Tooltip Text" data-toggle="tooltip"`, etc) * added directive to abstractField * implemented directive in various core fields as an example of usage * updated basic/app.vue with samples
icebob
left a comment
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.
Please add relevant tests too.
lionel-bijaoui
left a comment
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 sorry, I don't really understand the use of this feature.
It is to add attribute of a field, but why ? What is the use case ? It will need to be added to every existing, future and custom fields, so I need more information.
Thanks !
|
@lionel-bijaoui it allows you to add custom attributes to the components elements. So, for example, you can add I created this as a directive, attached to abstractField, so that it is as reusable as possible ... you just have to use I've already updated all of the vfg-core components to support it with this PR. Optional components would still need to be updated, but my understanding is that those will be separated out into their own packages and most of them will likely get a pretty big overhaul so I'm leaving those alone for now, and focusing on "core". Example field schema: This has been requested a few times, and seems like a fairly generic feature to have available ... allowing developers to associated any misc attributes they want with elements contained within VFG, which would allow them the ability to attach third-party libraries like Bootstrap Tooltips, etc without writing custom components. |
|
Ok, I didn't think about third party libraries. I like your solution (very elegant and simple), but something bugs me, and I don't know what. |
|
@lionel-bijaoui the directive seemed like the best way to implement this. I had considered using something like Is there any particular reason you dislike the directive approach? I'm fairly new to Vue and am not sure if there is an issue with directives. As for the "fieldOptions" bit, I'm open to suggestions here ...
Currently, I had also considered something like But wasn't keen on this approach as it added numerous top-level properties to the schema object, ... though these could be placed inside of Open to any suggestions you may have ... |
* v3: added brackets to conditional cleaned up the "clean up"
|
@zoul0813 I didn't think about reactivity, so I agree with you solution with the directive. Since attribute is not always the same, I'm thinking about putting it here, but I'm not sure to be honest. It could become a top-level property alongside TL:DR I hesitate between {
type: "input",
model: "name",
label: "Name",
fieldsOptions: {
inputType: "text"
},
attributes: {
wrapper: { "data-toggle": "collapse" },
input: { "data-toggle": "tooltip", "title": "Some custom tooltip title" },
label: { "custom-attr": "custom-value" }
}
}or {
type: "input",
model: "name",
label: "Name",
fieldsOptions: {
inputType: "text",
attributes: {
wrapper: { "data-toggle": "collapse" },
input: { "data-toggle": "tooltip", "title": "Some custom tooltip title" },
label: { "custom-attr": "custom-value" }
}
}
} |
|
Personally, I think the top-level property is best, as it is a "common" functionality and is not dynamic or dependent upon the field ... My biggest issue though, is the structure ... it seems "off", and I'm not sure how to make it "right". I really don't like the wrapper/input/label/whatever structure ... but I'm struggling to find a better way to present this so that developers can attach custom attributes to the various 'important' elements of a field ... obviously, the |
|
Yes, you are right, it is a top-level attribute. |
|
@lionel-bijaoui I've already added some tests - do you feel that more are needed? If so, could you assist with that?
|
lionel-bijaoui
left a comment
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.
created a new "attributes" directive that binds input/wrapper (with support for other named sets) attributes to elements to support dynamic attributes (such as
title="Tooltip Text" data-toggle="tooltip", etc)