Skip to content

Commit

Permalink
CrmUI - Improve crmUiEditable to support placeholders, and use its ow…
Browse files Browse the repository at this point in the history
…n css

Now this widget supports having a `placeholder`.
Also gave it its own css instead of piggybacking off crm-editable classes,
as that was a bit messy and Shoreditch was applying some extra stuff which
then had to be undone.
  • Loading branch information
colemanw committed Mar 20, 2022
1 parent 5e42208 commit 666a68e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
24 changes: 24 additions & 0 deletions ang/crmUI.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* CSS rules for Angular module "crmUI" */

/* In-place edit */
.crm-container [crm-ui-editable] {
padding-left: 2px;
border: 2px dashed transparent;
}
.crm-container [crm-ui-editable]:hover,
.crm-container [crm-ui-editable]:focus {
border: 2px dashed #d1d1d1;
cursor: pointer;
background-color: white !important;
color: initial !important;
}
.crm-container span[crm-ui-editable] {
display: inline-block !important;
padding-right: 2px;
min-height: 1em;
min-width: 3em;
}
.crm-container [crm-ui-editable]:empty:before {
content: attr(placeholder);
color: #9a9a9a;
}
1 change: 1 addition & 0 deletions ang/crmUi.ang.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
'ext' => 'civicrm',
'js' => ['ang/crmUi.js'],
'partials' => ['ang/crmUi'],
'css' => ['ang/crmUI.css'],
'requires' => array_merge(
[
'crmResource',
Expand Down
8 changes: 5 additions & 3 deletions ang/crmUi.js
Original file line number Diff line number Diff line change
Expand Up @@ -1107,8 +1107,10 @@
};
})

// Editable text using ngModel & html5 contenteditable
// Usage: <span crm-ui-editable ng-model="my.data">{{ my.data }}</span>
// Single-line editable text using ngModel & html5 contenteditable
// Supports a `placeholder` attribute which shows up if empty and no `default-value`.
// The `default-value` attribute will force a value if empty (mutually-exclusive with `placeholder`).
// Usage: <span crm-ui-editable ng-model="model.text" placeholder="Enter text"></span>
.directive("crmUiEditable", function() {
return {
restrict: "A",
Expand Down Expand Up @@ -1150,7 +1152,7 @@
scope.$apply(read);
});

element.attr('contenteditable', 'true').addClass('crm-editable-enabled');
element.attr('contenteditable', 'true');
}
};
})
Expand Down
1 change: 1 addition & 0 deletions ext/afform/admin/ang/afGuiEditor.css
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
#afGuiEditor .crm-editable-enabled:hover:not(:focus) {
border: 2px dashed grey !important;
}
/* Undo Shoreditch add-ons */
#afGuiEditor .crm-editable-enabled:before,
#afGuiEditor .crm-editable-enabled:after {
content: '';
Expand Down
1 change: 1 addition & 0 deletions ext/search_kit/css/crmSearchAdmin.css
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@
#bootstrap-theme.crm-search .crm-editable-enabled:hover:not(:focus) {
border: 2px dashed grey !important;
}
/* Undo Shoreditch add-ons */
#bootstrap-theme.crm-search .crm-editable-enabled:before,
#bootstrap-theme.crm-search .crm-editable-enabled:after {
content: '';
Expand Down

0 comments on commit 666a68e

Please sign in to comment.