-
Notifications
You must be signed in to change notification settings - Fork 649
fieldId()'s for names and ids #560
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
fieldId()'s for names and ids #560
Conversation
Edit: Sorry @plong I saw the former PR, you explained it there. Goldfish memory...
|
cheers :)
the 3 use cases I've implemented with it: |
I've found this pull request after looking for a solution to the unique identifier problem I have. Some bootstrap decorators use |
@AndyStricker hey that would be awesome if you could help get this merged! :) I've just been using my forked branch for this + a couple other changes/fixes I needed for my project. I would be really happy if they could all get merged and I could come back to the official repo. |
@plong0 @AndyStricker I'll take a look tomorrow, I actually implemented something similar for the Material decorator already, so I'm sure we can get something in a release soon. |
@Anthropic: Thanks for the hint, do you mean the |
Yes, the idea is if it is filter based then it can be made up to the user if they want to include form name. |
@AndyStricker have you tried using this PR? |
Update: I implemented a filter in bootstrap-decorator.js based on sfCamelKey that accepts an optional prefix argument to feed something like formCtrl.$name. I have not tested it yet. (I took this as opportunity to switch our code from the old boostrap-decorator to the new builder, but did not finish this yet). Should I add a protractor test? |
Words cannot express how much we love tests ;) |
Well the asf-bootstrap itself doesn't contain any karma/chia tests yet, only a protractor setup. I managed to run those tests without my changes, but two tests are failing. Still figuring out if it's my environment or not. A karma/chia test may be better suited to test a filter or controller method. Well I'm currently stuck. I've added a sfCamelKey filter to the .filter('sfCamelKey', function sfCamelKeyFilter() {
return function(formKey, prefix, postfix) {
if (!formKey) { return ''; };
var key = formKey.slice();
if (prefix) { key.unshift('' + prefix); }
if (postfix) { key.push('' + postfix); }
for (var i = 0; i < key.length; i++) {
var part = key[i].toLowerCase().split('');
if (i && part.length) { part[0] = part[0].toUpperCase(); };
key[i] = part.join('');
};
return key.join('');
};
}); So far so good, but we need a prefix, one that is distinguishable for form instances. I tried to access the form controller exposed at the scope: <label for="{{form.key | sfCamelKey:formCtrl.$name}}" ...>
<input id="{{form.key | sfCamelKey:formCtrl.$name}}" ...> But it looks like formCtrl is not always available (the directive configured it as Another possibility is to use the <label for="{{form.key | sfCamelKey:'input':$id}}" ...>
<input id="{{form.key | sfCamelKey:'input':$id}}" ...> The ugly part is: If the input is placed in a new scope (like ng-if does) we have to write I'm not sure if the filter approach is sufficient here or if we better use the |
@AndyStricker ah yes decorator tests differently. I was actually thinking of the fieldId() option being called within a filter, but same problem may exist. I wont have any time to think about it more until the weekend though. |
@AndyStricker @plong0 this is obviously long overdue, I've started updating the bootstrap decorator in the webpack branch, I agree that fieldId solution may indeed be the better approach, the only request I would have if either of you could help me further, is if we can get the fieldId function logic in the service file re-used for the decorator somehow to make sure changes only ever have to be done once, then I am happy to add it and start migrating the bootstrap webpack branch over to use it. |
@Anthropic Great to hear this. I'll look into this around next week. |
scope.form.key doesn't return numbers in the new builder so I have had to make a controller and decorator to comprehend what the current actual key is. I nearly have this working, just need to test it some more during the week. |
This should be working in the current develop branch, please let me know if anyone has suggestions on how it could/should be changed or altered. |
decorators should be updated (typically) by:
replacing:
form.key.slice(-1)[0]
with:
fieldId()
in name attributesfieldId(true)
in id/for/aria-describedby attributes