how to prefill data with angucomplete plugin? - angularjs

I am using angular with angucomplete plugin. https://github.com/darylrowland/angucomplete
How do I prefill the value of the autcomplete textfield? I can't find the answer on the documentation. Is anyone have encounter the same problem and able to solve it?
example:
I am creating the form to add/edit product. product depends on the part. so the part is using angucomplete.
when "editing product" the angucomplete need to prefilled with the part from variable or data binding.
my code :
<div style="display:inline-block;" ng-repeat="part in Productparts">
<!--<input type="text" />-->
<div angucomplete id="autocompletefield{{part.counter}}" placeholder="part" pause="100" selectedObject="partSelectedObject" url="http//www.blablabla.com/part?keyword=" datafield="part" titlefield="name" minlength="2" inputclass="form-control form-control-small"></div>
</div>
now when I am editing the product, the angucomplete needs to prefilled with object part.name

The solution is that I have to update the plugin so it accept prefilled value.
in angucompletejs file in scope I add :
"initialValue": "#initialvalue"
and in link I add :
if($scope.initialValue){
$scope.searchStr = $scope.initialValue;
}
now I can use the initialValue attribute.
<div style="display:inline-block;" ng-repeat="part in Productparts">
<div angucomplete id="autocompletefield{{part.counter}}" placeholder="part" pause="100" selectedObject="partSelectedObject" url="http//www.blablabla.com/part?keyword=" datafield="part" titlefield="name" minlength="2" inputclass="form-control form-control-small" initialValue="{{part.name}}"></div>
</div>

Related

Disable tooltip "Please fill out this field" when not using <form> tag (DNN)

Setting 'novalidate' or 'formnovalidate' will NOT fix this issue
I'm using the framework DNN. This framework wraps each page in a form tag which breaks my custom forms. To get passed this I'm using ng-form on a tag. Because of this fix I always see the default tooltip even though I'm using bootstraps uib-tooltip. I'm willing to go as far as jQuery to fix this issue however I read a post where apparently Chrome and Firefox have both disabled the ability to select and edit the default tooltips. Example:
<div role="form" ng-form="myForm" novalidate>
<div class="form-group">
<label>
<input type="text" id="Identifier" name="Identifier" ng-minlength="3" ng-maxlength="14" class="form-control" ng-model="$ctrl.Identifier" ng-required="true" uib-tooltip="{{ $ctrl.tooltips.identifier }}" tooltip-enable="myForm.Identifier.$invalid && myForm.Identifier.$touched">
</label>
</div>
</div>
Displays "Please fill out this field". How can I remove the default tooltip?
Thanks to this post by jscher2000 I was able to find a work around. Simply add a 'title' tag and set it's contents to an empty space. Simply passing in empty quotes doesn't work there must be at least 1 space between the quotes that's empty. Example:
<input type="text" name="Name" title=" ">
Thanks.

Validate textarea with Angular ng-messages when using Tinymce (ui-tinymce)

How to validate using ng-messages like ng-maxlength when the <textarea> has a ui-tinymce attribute?
Or is there a better way?
<div class="form-group">
<div class="col-sm-12">
<label>Description</label>
<p class="small">Please provide as much detailed information as possible.</p>
<textarea name="description" class="form-control required" ui-tinymce="tinymceOptions" ng-model="aC.testData.description"
ng-maxlength="100" required></textarea>
<div class="help-block" ng-messages="mainForm.description.$error" ng-show="mainForm.description.$touched">
<p ng-message="required">A description is required.</p>
<p ng-message="maxlength">Description must not exceed 100 characters.</p>
</div>
</div>
</div>
The issue you are seeing is that the standard directives just count characters so a simple (empty) HTML sample:
<p></p>
Would indeed show as 7 characters when in reality there is no "visible" content. I built a custom directive for another editor and what I ended up doing is using jQuery's .text() function against the HTML. This removes all of the HTML tags and provides an approximation for the number of actual text characters in the editor. This is a portion of the code in the diective:
var jStrippedString = jQuery(modelValue).text().trim();
return (maxlength < 0) || ngModelCtrl.$isEmpty(jStrippedString) || (jStrippedString.length <= maxlength);
I believe that you would want to create a custom Attribute directive that allows you to grab the model data for the editor and perform this validation yourself.
Adding forced_root_block: "" to the tinymce options should also work. By default it will not add <p></p> from the start.

angularjs xeditable and angularjs ui-tinymce together in an editable form

Is the a way to make a textarea ui-tinymce part of and an editable-form?.
I found a workaround by making ng-model of the editable-textarea and textarea ui-tinymce the same and then I hide the editable-textarea.
<form
onaftersave="onsave({$data:$data})"
editable-form
name="forms.{{formName}}"
>
<textarea ui-tinymce="tinymceOptions"
name="desccomp"
ng-model="item.desccomp">
</textarea>
<div
e-ng-show="false"
editable-textarea="item.desccomp"
e-name="desccomp"
>
</div>
</form>
Actually, TinyMCE already has inline abilities
https://www.tinymce.com/docs/demo/inline/
I'm facing same issue and thinking I'm gonna use only tinyMCE (with angular-ui-tinymce) leaving xeditable for this case).

Detecting value change in ng-model without using $watch and form for application having large number of models

My application has a lot of models in the page. I want to detect whether user has changed value of any model on click of save. Using $watch on every model puts too much load, so don't want to use this method. Is there any good approach for this?
Small snippet is like below:
<div>
<div class="ttere2">
<input type="radio" name="nc2-radio3" ng-model="nc2PenaltyAfter" value="specificDays" />
<input class="ggfe1" ng-model="nc2AfterDays" ng-disabled="nc2PenaltyAfter!='specificDays'" type="number" min="1" max="100" step="1" value="1" />days</div>
<div class="admin_wp-line">
<input type="radio" name="nc2-radio3" ng-model="nc2PenaltyAfter" value="immediately"/> Immediately </div>
<div class="acfv1">model 1</div>
</div>
<div style="margin-top: 20px;"><button ng-click="saveData();">Done</button></div>
............too many inputs go here
</div>
Use .$dirty! Angular will set this on every element that is bound using ng-model, automatically, when it has been changed. It will also set it on the entire form. You can access it in code like this:
if ($scope.myForm.$dirty) {
// Your code here
}
Angular will provide six useful variables on the form, and every ngModel-bound element in your form: $dirty and $pristine, $valid and $invalid, and $touched and $untouched. You can mix and match these to drive a lot of useful behaviors, and they're available both in your controller (using the expression shown above) and your template (directly).

AngularJS Form is not in HTML

I am trying to use AngularJS Validation in order to validate a simple form, however I was having troubles getting my ng-class to show the correct class based off whether or not the input was dirty or not. Then when I looked at the actual HTML of the page, the <form> tags are not even in the document at all!
<form novalidate name="infoForm">
<p>To start, provide some basic information about the project.</p>
<ul class="ulFormGeneral">
<li>
<label>Company name</label>
<input id="CompanyName" ng-class="{ cvError : infoForm.CompanyName.$dirty }" ng-model="form.CompanyName" name="CompanyName" maxlength="100" type="text" required />
</li>
</ul>
</form>
I want the cvError class to be added to this input if it is dirty, but nothing happens when I look at this in the browser. What am I doing wrong that is causing the <form> to just leave the DOM and then not work with my Angular expressions?
Welcome to the Angular world, no forms required! Here, the model is king. It looks like the problem is the ng-model and ng-class are point at different places.
Point everything at form.CompanyName (assuming that is the model name is form in the $scope):
<input id="CompanyName" ng-class="{ cvError : form.CompanyName.$dirty }" ng-model="form.CompanyName" name="CompanyName" maxlength="100" type="text" required />
The ng-model binds to the $scope. When you change the input field, it is automatically updated in the $scope. No form is needed or hitting a submit button to get the data. The $scope is updated with each key stroke.
The controller should do the work of figuring out what to do with the changes in the model. For example, you can add an ng-click to a button that fires a function defined by the controller to save the model.

Resources