-
Notifications
You must be signed in to change notification settings - Fork 724
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
Show help text alongside field if specified #1150
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Help text for a form field. | ||
* | ||
* @example <ma-help-text field="field"></ma-help-text> | ||
* | ||
* @param field.helpText() If a string, it will be displayed as text to the user. | ||
* If an `angular.element`, it will be compiled and displayed. | ||
* You can use "entry.values[x]" to check the current value | ||
* of property "x" (e.g. if you want to give different hints) | ||
*/ | ||
export default function maHelpText($compile) { | ||
return { | ||
scope: true, | ||
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. Please add a comment to tell that you need parent scope in case of it is a custom directive. |
||
restrict: 'E', | ||
link: function(scope, element) { | ||
var field = scope.field; | ||
|
||
var helpText = field && field.helpText(); | ||
if (helpText && typeof helpText === "object" && helpText.contents) { | ||
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. It should be the default case. First, I would test if helpText is a string, then a function, then consider it is a custom directive. |
||
// looks like an angular.element: | ||
element.append(helpText.clone()); | ||
$compile(element.contents())(scope); | ||
} else { | ||
// treat as plain text: | ||
scope.helpText = helpText; | ||
} | ||
}, | ||
template: '<small ng-if="helpText" class="help-block">{{ helpText }}</small>' | ||
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. Can you rename class to |
||
}; | ||
} | ||
|
||
maHelpText.$inject = ['$compile']; |
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.
Use new admin-config release once your marmelab/admin-config#72 PR has been released.