From 3e3fd8e86373a685786aa0a5296078cde020fef2 Mon Sep 17 00:00:00 2001 From: Steve Halford Date: Tue, 12 Jul 2016 15:18:58 +0100 Subject: [PATCH 1/3] Show help text alongside field if specified --- package.json | 2 +- src/javascripts/ng-admin/Crud/CrudModule.js | 1 + .../Crud/fieldView/BooleanFieldView.js | 1 + .../Crud/fieldView/ChoiceFieldView.js | 2 +- .../Crud/fieldView/ChoicesFieldView.js | 2 +- .../ng-admin/Crud/fieldView/DateFieldView.js | 2 +- .../Crud/fieldView/DateTimeFieldView.js | 2 +- .../ng-admin/Crud/fieldView/EmailFieldView.js | 2 +- .../Crud/fieldView/EmbeddedListFieldView.js | 2 +- .../ng-admin/Crud/fieldView/FileFieldView.js | 2 +- .../ng-admin/Crud/fieldView/FloatFieldView.js | 2 +- .../ng-admin/Crud/fieldView/JsonFieldView.js | 2 +- .../Crud/fieldView/NumberFieldView.js | 2 +- .../Crud/fieldView/PasswordFieldView.js | 2 +- .../Crud/fieldView/ReferenceFieldView.js | 2 +- .../Crud/fieldView/ReferenceManyFieldView.js | 2 +- .../Crud/fieldView/ReferencedListFieldView.js | 2 +- .../Crud/fieldView/StringFieldView.js | 2 +- .../ng-admin/Crud/fieldView/TextFieldView.js | 2 +- .../Crud/fieldView/WysiwygFieldView.js | 2 +- .../ng-admin/Crud/misc/maHelpText.js | 20 +++++++++++++++++++ 21 files changed, 40 insertions(+), 18 deletions(-) create mode 100644 src/javascripts/ng-admin/Crud/misc/maHelpText.js diff --git a/package.json b/package.json index 883c9b1a..9190b1cc 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "url": "git://github.com/marmelab/ng-admin.git" }, "devDependencies": { - "admin-config": "^0.11.0", + "admin-config": "stevehalford/admin-config#field-descriptions", "angular": "~1.4.8", "angular-mocks": "~1.4.8", "angular-numeraljs": "^1.1.6", diff --git a/src/javascripts/ng-admin/Crud/CrudModule.js b/src/javascripts/ng-admin/Crud/CrudModule.js index 3342aead..a93882a4 100644 --- a/src/javascripts/ng-admin/Crud/CrudModule.js +++ b/src/javascripts/ng-admin/Crud/CrudModule.js @@ -81,6 +81,7 @@ CrudModule.directive('maViewBatchActions', require('./button/maViewBatchActions' CrudModule.directive('maShowItem', require('./show/maShowItem')); CrudModule.directive('maViewActions', require('./misc/ViewActions')); CrudModule.directive('compile', require('./misc/Compile')); +CrudModule.directive('maHelpText', require('./misc/maHelpText')); CrudModule.config(require('./routing')); CrudModule.config(require('./config/factories')); diff --git a/src/javascripts/ng-admin/Crud/fieldView/BooleanFieldView.js b/src/javascripts/ng-admin/Crud/fieldView/BooleanFieldView.js index 2dd9539d..5e788f1e 100644 --- a/src/javascripts/ng-admin/Crud/fieldView/BooleanFieldView.js +++ b/src/javascripts/ng-admin/Crud/fieldView/BooleanFieldView.js @@ -5,5 +5,6 @@ export default { getWriteWidget: () => `
+
` }; diff --git a/src/javascripts/ng-admin/Crud/fieldView/ChoiceFieldView.js b/src/javascripts/ng-admin/Crud/fieldView/ChoiceFieldView.js index cfa406f8..516c8d40 100644 --- a/src/javascripts/ng-admin/Crud/fieldView/ChoiceFieldView.js +++ b/src/javascripts/ng-admin/Crud/fieldView/ChoiceFieldView.js @@ -2,5 +2,5 @@ export default { getReadWidget: () => '', getLinkWidget: () => '' + module.exports.getReadWidget() + '', getFilterWidget: () => '', - getWriteWidget: () => '' + getWriteWidget: () => ' ' }; diff --git a/src/javascripts/ng-admin/Crud/fieldView/ChoicesFieldView.js b/src/javascripts/ng-admin/Crud/fieldView/ChoicesFieldView.js index e8421275..469b7ba0 100644 --- a/src/javascripts/ng-admin/Crud/fieldView/ChoicesFieldView.js +++ b/src/javascripts/ng-admin/Crud/fieldView/ChoicesFieldView.js @@ -2,5 +2,5 @@ export default { getReadWidget: () => '', getLinkWidget: () => '' + module.exports.getReadWidget() + '', getFilterWidget: () => '', - getWriteWidget: () => '' + getWriteWidget: () => ' ' }; diff --git a/src/javascripts/ng-admin/Crud/fieldView/DateFieldView.js b/src/javascripts/ng-admin/Crud/fieldView/DateFieldView.js index d3f31ae6..63b49dd6 100644 --- a/src/javascripts/ng-admin/Crud/fieldView/DateFieldView.js +++ b/src/javascripts/ng-admin/Crud/fieldView/DateFieldView.js @@ -2,5 +2,5 @@ export default { getReadWidget: () => '', getLinkWidget: () => '' + module.exports.getReadWidget() + '', getFilterWidget: () => '', - getWriteWidget: () => '
' + getWriteWidget: () => '
' }; diff --git a/src/javascripts/ng-admin/Crud/fieldView/DateTimeFieldView.js b/src/javascripts/ng-admin/Crud/fieldView/DateTimeFieldView.js index 8aceaf87..ae613940 100644 --- a/src/javascripts/ng-admin/Crud/fieldView/DateTimeFieldView.js +++ b/src/javascripts/ng-admin/Crud/fieldView/DateTimeFieldView.js @@ -2,5 +2,5 @@ export default { getReadWidget: () => '', getLinkWidget: () => '' + module.exports.getReadWidget() + '', getFilterWidget: () => '', - getWriteWidget: () => '
' + getWriteWidget: () => '
' }; diff --git a/src/javascripts/ng-admin/Crud/fieldView/EmailFieldView.js b/src/javascripts/ng-admin/Crud/fieldView/EmailFieldView.js index 918da90e..87ad29b7 100644 --- a/src/javascripts/ng-admin/Crud/fieldView/EmailFieldView.js +++ b/src/javascripts/ng-admin/Crud/fieldView/EmailFieldView.js @@ -2,5 +2,5 @@ export default { getReadWidget: () => '', getLinkWidget: () => '' + module.exports.getReadWidget() + '', getFilterWidget: () => '', - getWriteWidget: () => '' + getWriteWidget: () => ' ' }; diff --git a/src/javascripts/ng-admin/Crud/fieldView/EmbeddedListFieldView.js b/src/javascripts/ng-admin/Crud/fieldView/EmbeddedListFieldView.js index cbb71370..870d7f7c 100644 --- a/src/javascripts/ng-admin/Crud/fieldView/EmbeddedListFieldView.js +++ b/src/javascripts/ng-admin/Crud/fieldView/EmbeddedListFieldView.js @@ -2,5 +2,5 @@ export default { getReadWidget: () => '', getLinkWidget: () => 'error: cannot display referenced_list field as linkable', getFilterWidget: () => 'error: cannot display referenced_list field as filter', - getWriteWidget: () => '' + getWriteWidget: () => ' ' }; diff --git a/src/javascripts/ng-admin/Crud/fieldView/FileFieldView.js b/src/javascripts/ng-admin/Crud/fieldView/FileFieldView.js index 2ef1b0d9..24197320 100644 --- a/src/javascripts/ng-admin/Crud/fieldView/FileFieldView.js +++ b/src/javascripts/ng-admin/Crud/fieldView/FileFieldView.js @@ -2,5 +2,5 @@ export default { getReadWidget: () => 'error: cannot display file field as readable', getLinkWidget: () => 'error: cannot display file field as linkable', getFilterWidget: () => 'error: cannot display file field as filter', - getWriteWidget: () => '' + getWriteWidget: () => ' ' }; diff --git a/src/javascripts/ng-admin/Crud/fieldView/FloatFieldView.js b/src/javascripts/ng-admin/Crud/fieldView/FloatFieldView.js index fe1c6724..9fdb6f07 100644 --- a/src/javascripts/ng-admin/Crud/fieldView/FloatFieldView.js +++ b/src/javascripts/ng-admin/Crud/fieldView/FloatFieldView.js @@ -2,5 +2,5 @@ export default { getReadWidget: () => '', getLinkWidget: () => '' + module.exports.getReadWidget() + '', getFilterWidget: () => '', - getWriteWidget: () => '' + getWriteWidget: () => ' ' }; diff --git a/src/javascripts/ng-admin/Crud/fieldView/JsonFieldView.js b/src/javascripts/ng-admin/Crud/fieldView/JsonFieldView.js index 035e61e7..2a9c320e 100644 --- a/src/javascripts/ng-admin/Crud/fieldView/JsonFieldView.js +++ b/src/javascripts/ng-admin/Crud/fieldView/JsonFieldView.js @@ -2,5 +2,5 @@ export default { getReadWidget: () => '', getLinkWidget: () => 'error: cannot display a json field as linkable', getFilterWidget: () => '', - getWriteWidget: () => '' + getWriteWidget: () => ' ' }; diff --git a/src/javascripts/ng-admin/Crud/fieldView/NumberFieldView.js b/src/javascripts/ng-admin/Crud/fieldView/NumberFieldView.js index a357eb26..3ad4b4ab 100644 --- a/src/javascripts/ng-admin/Crud/fieldView/NumberFieldView.js +++ b/src/javascripts/ng-admin/Crud/fieldView/NumberFieldView.js @@ -2,5 +2,5 @@ export default { getReadWidget: () => '', getLinkWidget: () => '' + module.exports.getReadWidget() + '', getFilterWidget: () => '', - getWriteWidget: () => '' + getWriteWidget: () => ' ' }; diff --git a/src/javascripts/ng-admin/Crud/fieldView/PasswordFieldView.js b/src/javascripts/ng-admin/Crud/fieldView/PasswordFieldView.js index 0c2aa113..a8e53dc0 100644 --- a/src/javascripts/ng-admin/Crud/fieldView/PasswordFieldView.js +++ b/src/javascripts/ng-admin/Crud/fieldView/PasswordFieldView.js @@ -2,5 +2,5 @@ export default { getReadWidget: () => 'error: cannot display password field as readable', getLinkWidget: () => 'error: cannot display password field as linkable', getFilterWidget: () => 'error: cannot display password field as filter', - getWriteWidget: () => '' + getWriteWidget: () => ' ' }; diff --git a/src/javascripts/ng-admin/Crud/fieldView/ReferenceFieldView.js b/src/javascripts/ng-admin/Crud/fieldView/ReferenceFieldView.js index c44284dd..536f64ec 100644 --- a/src/javascripts/ng-admin/Crud/fieldView/ReferenceFieldView.js +++ b/src/javascripts/ng-admin/Crud/fieldView/ReferenceFieldView.js @@ -2,5 +2,5 @@ export default { getReadWidget: () => '', getLinkWidget: () => '', getFilterWidget: () => '', - getWriteWidget: () => '' + getWriteWidget: () => ' ' }; diff --git a/src/javascripts/ng-admin/Crud/fieldView/ReferenceManyFieldView.js b/src/javascripts/ng-admin/Crud/fieldView/ReferenceManyFieldView.js index 98023995..190600ee 100644 --- a/src/javascripts/ng-admin/Crud/fieldView/ReferenceManyFieldView.js +++ b/src/javascripts/ng-admin/Crud/fieldView/ReferenceManyFieldView.js @@ -2,5 +2,5 @@ export default { getReadWidget: () => '', getLinkWidget: () => '', getFilterWidget: () => '', - getWriteWidget: () => '' + getWriteWidget: () => ' ' }; diff --git a/src/javascripts/ng-admin/Crud/fieldView/ReferencedListFieldView.js b/src/javascripts/ng-admin/Crud/fieldView/ReferencedListFieldView.js index c6686002..a1c33c55 100644 --- a/src/javascripts/ng-admin/Crud/fieldView/ReferencedListFieldView.js +++ b/src/javascripts/ng-admin/Crud/fieldView/ReferencedListFieldView.js @@ -2,5 +2,5 @@ export default { getReadWidget: () => '', getLinkWidget: () => 'error: cannot display referenced_list field as linkable', getFilterWidget: () => 'error: cannot display referenced_list field as filter', - getWriteWidget: () => '' + getWriteWidget: () => ' ' }; diff --git a/src/javascripts/ng-admin/Crud/fieldView/StringFieldView.js b/src/javascripts/ng-admin/Crud/fieldView/StringFieldView.js index 066dc0bf..5472a786 100644 --- a/src/javascripts/ng-admin/Crud/fieldView/StringFieldView.js +++ b/src/javascripts/ng-admin/Crud/fieldView/StringFieldView.js @@ -2,5 +2,5 @@ export default { getReadWidget: () => '', getLinkWidget: () => '' + module.exports.getReadWidget() + '', getFilterWidget: () => '', - getWriteWidget: () => '' + getWriteWidget: () => ' ' }; diff --git a/src/javascripts/ng-admin/Crud/fieldView/TextFieldView.js b/src/javascripts/ng-admin/Crud/fieldView/TextFieldView.js index 7d89f016..9b6ccee5 100644 --- a/src/javascripts/ng-admin/Crud/fieldView/TextFieldView.js +++ b/src/javascripts/ng-admin/Crud/fieldView/TextFieldView.js @@ -2,5 +2,5 @@ export default { getReadWidget: () => '', getLinkWidget: () => '' + module.exports.getReadWidget() + '', getFilterWidget: () => '', - getWriteWidget: () => '' + getWriteWidget: () => ' ' }; diff --git a/src/javascripts/ng-admin/Crud/fieldView/WysiwygFieldView.js b/src/javascripts/ng-admin/Crud/fieldView/WysiwygFieldView.js index fe91422f..e794ce2a 100644 --- a/src/javascripts/ng-admin/Crud/fieldView/WysiwygFieldView.js +++ b/src/javascripts/ng-admin/Crud/fieldView/WysiwygFieldView.js @@ -2,5 +2,5 @@ export default { getReadWidget: () => '', getLinkWidget: () => '' + module.exports.getReadWidget() + '', getFilterWidget: () => '', - getWriteWidget: () => '' + getWriteWidget: () => ' ' }; diff --git a/src/javascripts/ng-admin/Crud/misc/maHelpText.js b/src/javascripts/ng-admin/Crud/misc/maHelpText.js new file mode 100644 index 00000000..420b3bff --- /dev/null +++ b/src/javascripts/ng-admin/Crud/misc/maHelpText.js @@ -0,0 +1,20 @@ +/** + * Help text for a form field. + * + * @example + */ +export default function maHelpText() { + return { + scope: { + 'field': '&' + }, + restrict: 'E', + link: function(scope, element) { + var field = scope.field(); + scope.helpText = field.helpText(); + }, + template: '{{ helpText }}' + }; +} + +maHelpText.$inject = []; From e0ad410029f633bd66ada450b384afbf2d46a289 Mon Sep 17 00:00:00 2001 From: Steve Halford Date: Tue, 12 Jul 2016 15:54:37 +0100 Subject: [PATCH 2/3] Add helpText to documentation --- doc/reference/Field.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/reference/Field.md b/doc/reference/Field.md index 74247379..46263beb 100644 --- a/doc/reference/Field.md +++ b/doc/reference/Field.md @@ -173,6 +173,9 @@ Define the default value of the field in the creation form. * `pinned(boolean)` Whether the field should always appear. Used in filters (see listView Settings). Default to false. +* `helpText(string)` +Define help text to be shown under the field in `editionView` and `creationView`. + ## `wysiwyg` Field Type * `stripTags(boolean)` From 741dd4136d3bdfe40f65b3a638b33a88ca322243 Mon Sep 17 00:00:00 2001 From: Richard Bradley Date: Wed, 3 Aug 2016 15:54:01 +0100 Subject: [PATCH 3/3] Allow angular code in Field.helpText --- .../ng-admin/Crud/misc/maHelpText.js | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/javascripts/ng-admin/Crud/misc/maHelpText.js b/src/javascripts/ng-admin/Crud/misc/maHelpText.js index 420b3bff..12701e33 100644 --- a/src/javascripts/ng-admin/Crud/misc/maHelpText.js +++ b/src/javascripts/ng-admin/Crud/misc/maHelpText.js @@ -2,19 +2,31 @@ * Help text for a form field. * * @example + * + * @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() { +export default function maHelpText($compile) { return { - scope: { - 'field': '&' - }, + scope: true, restrict: 'E', link: function(scope, element) { - var field = scope.field(); - scope.helpText = field.helpText(); + var field = scope.field; + + var helpText = field && field.helpText(); + if (helpText && typeof helpText === "object" && helpText.contents) { + // looks like an angular.element: + element.append(helpText.clone()); + $compile(element.contents())(scope); + } else { + // treat as plain text: + scope.helpText = helpText; + } }, template: '{{ helpText }}' }; } -maHelpText.$inject = []; +maHelpText.$inject = ['$compile'];