-
Notifications
You must be signed in to change notification settings - Fork 90
Convert patternfly.form module directives to components. #375
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
Merged
dgutride
merged 3 commits into
patternfly:branch-4.0-dev
from
jeff-phillips-18:branch-4.0-dev
Dec 21, 2016
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* @ngdoc directive | ||
* @name patternfly.form.directive:pfFormGroup | ||
* @restrict E | ||
* | ||
* @description | ||
* Encapsulates the structure and styling for a label + input used within a | ||
* Bootstrap3 based form. | ||
* | ||
* This directive creates new scope. | ||
* | ||
* @param {string} pfLabel the text for the <label> element. | ||
* @param {string} pfFieldId the id of the form field. Default value is id of the form field element. | ||
* @param {string} pfLabelClass the class of the label element. Default value is "col-sm-2". | ||
* @param {string} pfInputClass the class of the input element. Default value is "col-sm-5". | ||
* | ||
* @example | ||
<example module="patternfly.form"> | ||
|
||
<file name="index.html"> | ||
<div ng-controller="FormDemoCtrl"> | ||
<p>Name: {{ item.name }}</p> | ||
<p>Description: {{ item.description }}</p> | ||
<form> | ||
<pf-form-group pf-label="Name" required> | ||
<input id="name" name="name" ng-model="item.name" type="text" required/> | ||
</pf-form-group> | ||
<pf-form-group pf-label="Description"> | ||
<textarea id="description" name="description" ng-model="item.description"> | ||
{{ item.description }} | ||
</textarea> | ||
</pf-form-group> | ||
</form> | ||
<p>Horizontal Form</p> | ||
<form class="form-horizontal"> | ||
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. Should this be updated to reflect the discussed changes to |
||
<pf-form-group pf-label="Name" required pf-label-class="col-sm-2" pf-input-class="col-sm-5"> | ||
<input id="name" name="name" ng-model="item.name" type="text" required/> | ||
</pf-form-group> | ||
<pf-form-group pf-label="Description" pf-label-class="col-sm-2" pf-input-class="col-sm-5"> | ||
<textarea id="description" name="description" ng-model="item.description"> | ||
{{ item.description }} | ||
</textarea> | ||
</pf-form-group> | ||
</form> | ||
</div> | ||
</file> | ||
|
||
<file name="script.js"> | ||
angular.module( 'patternfly.form' ).controller( 'FormDemoCtrl', function( $scope ) { | ||
$scope.item = { | ||
name: 'Homer Simpson', | ||
description: 'I like donuts and Duff. Doh!' | ||
}; | ||
}); | ||
</file> | ||
</example> | ||
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/** | ||
* @ngdoc directive | ||
* @name patternfly.form.directive:pfRemainingCharsCount | ||
* | ||
* @description | ||
* Directive for showing a characters remaining count and triggering warning and error</br> | ||
* behavior when passing specified thresholds. When the <code>chars-warn-remaining</code> threshold is passed, </br> | ||
* the <code>chars-warn-remaining-pf</code> css class is applied to the <code>count-fld</code>, which by default, turns </br> | ||
* the remaining count number <font color='red'>red</font>.</br> | ||
* By default, characters may be entered into the text field after the <code>chars-max-limit</code> limit has been reached,</br> | ||
* the remaining count number will become a negative value. Setting the <code>blockInputAtMaxLimit</code> to <em>true</em>,</br> | ||
* will block additional input into the text field after the max has been reached; additionally a right-click 'paste' will only </br> | ||
* paste characters until the maximum character limit is reached. | ||
* | ||
* @param {string} ng-model The scope model variable which contains the initial text for the text field. Required, but</br> | ||
* can be an emptly string (""). | ||
* @param {string} count-fld The id of the field to display the 'characters-remaining' count. | ||
* @param {string} chars-max-limit Number representing the maximum number of characters to allow before dispatching a<br/> | ||
* 'overCharsMaxLimit' event. When the number of characters falls below <code>chars-max-limit</code>, a 'underCharsMaxLimit'<br/> | ||
* event is dispatched. | ||
* @param {string} chars-warn-remaining Number of remaining characters to warn upon. The 'chars-warn-remaining-pf'<br/> | ||
* class will be applied to the <code>count-fld</code> when the remaining characters is less than the<br/> | ||
* <code>chars-warn-remaining</code> threshold. When/if the number of remaining characters becomes greater than the<br/> | ||
* <code>chars-warn-remaining</code> threshold, the 'chars-warn-remaining-pf' class is removed from the <code>count-fld</code> field. | ||
* @param {boolean=} block-input-at-max-limit If true, no more characters can be entered into the text field when the<br/> | ||
* <code>chars-max-limit</code> has been reached. If false (the default), characters may be entered into the text field after the<br/> | ||
* max. limit has been reached, but these additional characters will trigger the 'overCharsMaxLimit' event to be<br/> | ||
* dispatched. When <code>blockInputAtMaxLimit</code> is <em>true</em>, a right-click 'paste' will only paste<br/> | ||
* characters until the maximum character limit is reached. | ||
* | ||
* @example | ||
<example module="patternfly.example"> | ||
<file name="index.html"> | ||
<div ng-controller="DemoCtrl" style="display:inline-block; width: 100%;"> | ||
|
||
<style> | ||
textarea { | ||
resize: none; | ||
} | ||
</style> | ||
|
||
<div class="container"> | ||
<strong>Max limit: 20, warn when 5 or less remaining, disable button after max limit</strong> | ||
<div class="row"> | ||
<div class="col-md-4"> | ||
|
||
<form> | ||
<div class="form-group"> | ||
<label for="messageArea"></label> | ||
<textarea class="form-control" pf-remaining-chars-count id="messageArea_1" ng-model="messageArea1text" chars-max-limit="20" chars-warn-remaining="5" | ||
count-fld="charRemainingCntFld_1" name="text" placeholder="Type in your message" rows="5"></textarea> | ||
</div> | ||
<span class="pull-right chars-remaining-pf"> | ||
<span id="charRemainingCntFld_1"></span> | ||
<button id="postBtn_1" ng-disabled="charsMaxLimitExceeded" type="submit" class="btn btn-default">Post New Message</button> | ||
</span> | ||
</form> | ||
|
||
</div> | ||
</div> | ||
<br> | ||
<strong>Max limit: 10, warn when 2 or less remaining, block input after max limit</strong> | ||
<div class="row"> | ||
<div class="col-md-4"> | ||
<form> | ||
<div class="form-group"> | ||
<label for="messageArea"></label> | ||
<textarea class="form-control" pf-remaining-chars-count id="messageArea_2" ng-model="messageArea2text" chars-max-limit="10" chars-warn-remaining="2" | ||
block-input-at-max-limit="true" count-fld="charRemainingCntFld_2" name="text" | ||
placeholder="Type in your message" rows="5"></textarea> | ||
</div> | ||
<span class="pull-left"> | ||
<button id="postBtn_2" type="submit" class="btn btn-default">Submit</button> | ||
</span> | ||
<span class="pull-right chars-remaining-pf"> | ||
<span id="charRemainingCntFld_2"></span> | ||
</span> | ||
</form> | ||
</div> | ||
</div> | ||
<br> | ||
<strong>Max limit: 10, warn when 5 or less remaining, block input after max limit</strong> | ||
<div class="row"> | ||
<div class="col-md-4"> | ||
<input id="input_3" pf-remaining-chars-count chars-max-limit="10" ng-model="messageInput3text" chars-warn-remaining="5" count-fld="charRemainingCntFld_3" | ||
block-input-at-max-limit="true"/> | ||
<span class="chars-remaining-pf"><span id="charRemainingCntFld_3" style="padding-left: 5px"></span>Remaining</span> | ||
</div> | ||
</div> | ||
</div> | ||
</file> | ||
|
||
<file name="script.js"> | ||
angular.module( 'patternfly.example', ['patternfly.form']); | ||
|
||
angular.module( 'patternfly.example' ).controller( 'DemoCtrl', function( $scope ) { | ||
$scope.messageArea1text = "Initial Text"; | ||
$scope.messageArea2text = ""; | ||
$scope.messageInput3text = ""; | ||
|
||
$scope.charsMaxLimitExceeded = false; | ||
|
||
// 'tfId' will equal the id of the text area/input field which | ||
// triggered the event | ||
$scope.$on('overCharsMaxLimit', function (event, tfId) { | ||
if(!$scope.charsMaxLimitExceeded){ | ||
$scope.charsMaxLimitExceeded = true; | ||
} | ||
}); | ||
|
||
// 'tfId' will equal the id of the text area/input field which | ||
// triggered the event | ||
$scope.$on('underCharsMaxLimit', function (event, tfId) { | ||
if($scope.charsMaxLimitExceeded){ | ||
$scope.charsMaxLimitExceeded = false; | ||
} | ||
}); | ||
|
||
}); | ||
|
||
</file> | ||
</example> | ||
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
angular.module('patternfly.form').component('pfFormButtons', { | ||
|
||
bindings: { | ||
pfHandleCancel: '&pfOnCancel', | ||
pfHandleSave: '&pfOnSave', | ||
pfWorking: '=', | ||
pfButtonContainerClass: '@' | ||
}, | ||
require: { | ||
form: '^form' | ||
}, | ||
templateUrl: 'form/form-buttons/form-buttons.html', | ||
controller: function () { | ||
'use strict'; | ||
|
||
var ctrl = this; | ||
|
||
ctrl.$onInit = function () { | ||
if (ctrl.pfWorking === undefined) { | ||
ctrl.pfWorking = false; | ||
} | ||
|
||
angular.extend(ctrl, { | ||
isInvalid: isInvalid | ||
}); | ||
}; | ||
|
||
function isInvalid () { | ||
var invalid = ctrl.form.$invalid; | ||
|
||
if (ctrl.form && ctrl.form.name && ctrl.form.name.$error) { | ||
if (ctrl.form.name.$error.server) { | ||
invalid = false; | ||
} | ||
} | ||
|
||
return invalid; | ||
} | ||
} | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
angular.module('patternfly.form').component('pfFormGroup', { | ||
|
||
bindings: { | ||
pfLabel: '@', | ||
pfField: '@', | ||
pfLabelClass: '@', | ||
pfInputClass: '@' | ||
|
||
}, | ||
require: { | ||
form: '^form' | ||
}, | ||
transclude: true, | ||
templateUrl: 'form/form-group/form-group.html', | ||
|
||
controller: function ($element) { | ||
'use strict'; | ||
|
||
var ctrl = this; | ||
|
||
ctrl.$onInit = function () { | ||
angular.extend(ctrl, { | ||
hasErrors: hasErrors | ||
}); | ||
}; | ||
|
||
ctrl.$postLink = function () { | ||
var input = getInput($element); | ||
var type = input.attr('type'); | ||
|
||
if (['checkbox', 'radio', 'time'].indexOf(type) === -1) { | ||
input.addClass('form-control'); | ||
} | ||
|
||
if (!ctrl.pfField) { | ||
ctrl.pfField = input.attr('id'); | ||
} | ||
|
||
if (input.attr('required')) { | ||
$element.addClass('required'); | ||
} | ||
|
||
if (ctrl.form[ctrl.pfField]) { | ||
ctrl.error = ctrl.form[ctrl.pfField].$error; | ||
} | ||
}; | ||
|
||
function hasErrors () { | ||
return ctrl.form[ctrl.pfField] && ctrl.form[ctrl.pfField].$invalid && ctrl.form[ctrl.pfField].$dirty; | ||
} | ||
|
||
function getInput (element) { | ||
// table is used for bootstrap3 date/time pickers | ||
var input = element.find('table'); | ||
|
||
if (input.length === 0) { | ||
input = element.find('input'); | ||
|
||
if (input.length === 0) { | ||
input = element.find('select'); | ||
|
||
if (input.length === 0) { | ||
input = element.find('textarea'); | ||
} | ||
} | ||
} | ||
return input; | ||
} | ||
} | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
restrict E should be in the header