Review form using angular js - angularjs

I am trying to build an online store for my project, and i wish i could add a review form in one of my pages, i am getting a problem with inserting the input value into the array ! here is my files
details.html
<div class="col-sm-12">
<div class="row">
<div ng-controller="reviewController">
<h3 class="pdt-title">Review</h3><hr>
<div class="alert alert-danger" ng-if="reviews.length == 0">
No reviews yet, be the first to review this Product!
</div><br>
<div class="col-sm-12" ng-repeat="review in reviews" >
<blockquote class="row">
<h3 class="pdt-title col-sm-6">{{review.username}}</h3>
<h3 class="pdt-title col-sm-6">{{review.star}}</h3>
<h5 class="col-sm-12"><small><i>{{review.email}}</i></small></h5>
<p class="col-sm-12">{{review.message}}</p>
</blockquote>
</div>
<form class="form-inline form-group">
<div class="input-group">
<span class="input-group-addon">Name</span>
<input class="form-control" type="text" ng-model="username"></input>
<span class="input-group-addon">E-mail</span>
<input class="form-control" type="email" ng-model="email"></input>
<span class="input-group-addon">Star</span>
<select class="form-control" ng-model="star">
<option name="oneStar" value="1 star">1 Star</option>
<option name="twoStar" value="2 star">2 Star</option>
<option name="threeStar" value="3 star">3 Star</option>
<option name="fourStar" value="4 star">4 Star</option>
<option name="fiveStar" value="5 star">5 Star</option>
</select>
</div>
</form>
<textarea class="form-control" rows="5" ng-model="message"></textarea><br>
<input type="submit" class="btn btn-block btn-success" ng-submit="addReview()" value="Submit review"></input>
</div>
</div>
</div>
</div>
</div>
and here is my controller
app.js
app.controller('reviewController',function($scope){
$scope.reviews=[];
$scope.addReview=function(){
$scope.reviews.push({
name:$scope.username,
email:$scope.email,
star:$scope.star,
message:$scope.message
});
};
});
it would be great if someone explains the comments staying on the page even when the page is refreshed, usually the comments get lost when the page is refreshed.

As said in the comments, you should load your comments from somewhere. A service should do the job.
But your problem was with your ng-submit button. Didn't inspect in deep but I changed to ng-click and it worked. Also, be sure to always place your "fields" inside an object and not directly on the $scope.
//Set the models inside an object
$scope.review = {};
And then
<input class="form-control" type="text" ng-model="review.username" />
Here's an updated:
Fiddle
As an extra tip, if you haven't check this awesome guide yet you should save some time and read through it:
angular-styleguide
It contains a compilation of angular best practices written by John Papa.

Related

I have a form with input fields onclick save(submit) input fields data should be displayed in next page in a div

<div className="input_container">
<h1>Shipping Address</h1>
<div class="Contactus_table1_inputbox">
<h4>Full Name*</h4><br></br>
<input type="text" required="required"/>
</div>
<div class="Contactus_table1_inputbox">
<h4>Address Line*</h4><br></br>
<input type="text" required="required"/>
</div>
<div class="Contactus_table1_inputbox">
<h4>Zip/Postal Code*</h4><br></br>
<input type="text" required="required"/>
</div>
<div class="Contactus_table1_inputbox">
<h4>City*</h4><br></br>
<input type="text" required="required"/>
</div>
<div class="Contactus_table1_inputbox">
<h4>Country</h4><br></br>
<select>
<option className="option" value="" >India</option>
<option value="" >Australia</option>
<option value="" >France</option>
<option value="" >Germany</option>
<option value="" >Maldives</option>
</select>
</div>
<div className="container">
<div class="Contactus_table1_inputbox">
<h4>Email Address*</h4><br></br>
<input type="text" required="required"/>
</div>
<div id="phone_number" class="Contactus_table1_inputbox">
<h4>Phone Number*</h4><br></br>
<input type="text" required="required"/>
</div>
</div>
</div
// Think of a shopping website when you add your address to your order in payment page there will be summary of your shipping address and order id. I have to show it in another file.
<div className="payment_table2_box">
<h1>Shipping to</h1>
<h2>John Doe</h2>
<p>House no. 10, Amazing Building, Beautiful street, Near Ancient Landmark</p>
<h3>Hyderabad,123456</h3>
<h3>Telangana</h3>
<h3>+91 12345 78900</h3>
<a href="/Address" id="Learn_btn" >Edit</a>
<img id="edit_img" src="../images/edit_img.svg" alt="" />
</div>
// After submission Data should store locally and show in placeholders of payment_table2_box div.
You can make state global using contex api and push or redirect to the page where you want your data to be displayed and access data from context to display in the page.

angular not update file from app services

Does anyone know why angular does not update the file in the browser? I try to use the incognito also same. the file recently I update not reflect on the browser. ng-repeat.
the HTML:
<body ng-app="cgpaCalculator">
<div class="card" ng-controller="cgpaCtrl">
[...]
<div class="row" ng-repeat="number in data.rows track by $index">
<div class="col-lg-5 mb-2">
<div class="form-label-group">
<input type="text" name="course_name" id="course_name" class="form-control" placeholder="Course Name [Optional]">
<label for="course_name">Course Name [Optional]</label>
</div>
</div>
<div class="col-lg-3 mb-2">
<div class="form-label-group">
<select class="form-control custom-select" ng-model="data.rows[$index].grade" ng-options="grade for grade in grades track by grade">
<option value="" disabled selected>Select Grade</option>
</select>
</div>
</div>
</div>
The Controller:
I don't know what i'm doing wrong.

Using angular submit button causes redirect instead of calling function in SharePoint

I have a form within my angular app (within SharePoint) that uses routing via hashbang, but when I click on a button in my form, it redirects to the root (like it can't resolve the URL so it uses the otherwise setting in my config), instead of executing the function.
Here is the HTML (my controller is defined in the routing):
<form name="newItem" class="form-horizontal" data-ng-submit="createItem()">
<fieldset>
<div class="form-group">
<label class="col-lg-2 control-label" for="itemtype">Type *</label>
<div class="col-lg-10">
<select class="form-control" id="itemtype" data-ng-model="selectedType"
data-ng-options="opt as opt.label for opt in types" required>
<option style="display:none" value="">Select a type</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label" for="title">Title *</label>
<div class="col-lg-10">
<input class="form-control" name="title" id="title" type="text" data-ng-model="itemtitle" placeholder="Add your title (Limited to 70 characters)" data-ng-maxlength="70" required>
({{70 - newItem.title.$viewValue.length}} Characters Remaining)
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label" for="body">Body *</label>
<div class="col-lg-10">
<textarea class="form-control" name="body" id="body" data-ng-model="itembody" rows="4" placeholder="Add your body (Limited to 500 characters)" data-ng-maxlength="500" required> </textarea>
Your summary will be displayed as follows ({{500 - newItem.body.$viewValue.length}} Characters Remaining):<br /> {{itembody}}
</div>
</div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<button class="btn btn-default" data-ng-click="cancel()">Cancel</button>
<button class="btn btn-primary" data-ng-click="newItem">Submit</button>
</div>
</div>
</fieldset>
</form>
Here is my controller:
appControllers.controller('appItemPostCtrl', ['$scope', '$location', 'appItems', 'appTypes', function ($scope, $location, appItems, appTypes) {
var itemEntry = new appItems;
console.log(itemEntry);
$scope.types = [];
appTypes.query(function (typedata) {
var itemTypes = typedata.value;
// Foreach type, push values into types array
angular.forEach(itemTypes, function (typevalue, typekey) {
$scope.types.push({
label: typevalue.Title,
value: typevalue.Title,
});
})
});
$scope.createItem = function () {
itemEntry.Title = $scope.itemtitle;
itemEntry.$save();
}
$scope.cancel = function () {
}
}]);
UPDATE: It appears that this is related to SharePoint (My Angular Form is in SharePoint), as even setting the button type to submit as follows triggers the refresh instead of running the function. SharePoint is wrapping everything in a form since it inherits from the Master page of the Web, so when I added two "Angular Forms" to the page, the first angular form was closing the tag on the SharePoint form so the second was able to work. Does anyone have a stable workaround (beyond creating a custom masterpage). Image as follows:
I solved it by closing the tag of SharePoint instead of creating a custom masterpage. Ex:
<!-- Close the default form tag put in place by SharePoint instead of creating a custom Masterpage without this element that requires increased permissions and complexity to deploy. Without this tag closed, the form below will not render properly -->
</form>
<div>
<form id="newItemForm" class="form-horizontal" data-ng-submit="createItem()">
<div class="form-group">
<label class="col-lg-2 control-label" for="itemtype">Type *</label>
<div class="col-lg-10">
<select class="form-control" id="itemtype" data-ng-model="selectedType"
data-ng-options="opt as opt.label for opt in types" required>
<option style="display:none" value="">Select a type</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label" for="title">Title *</label>
<div class="col-lg-10">
<input class="form-control" name="title" id="title" type="text" data-ng-model="itemtitle" placeholder="Add your title (Limited to 70 characters)" data-ng-maxlength="70" required>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label" for="body">Body *</label>
<div class="col-lg-10">
<textarea class="form-control" name="body" id="body" data-ng-model="itembody" rows="4" placeholder="Add your body (Limited to 500 characters)" data-ng-maxlength="500" required> </textarea>
</div>
</div>
<div class="col-lg-10 col-lg-offset-2">
<!--<button type="button" class="btn btn-default" data-ng-click="cancel()">Cancel</button>-->
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
Add type='button' to the buttons. I had this same problem before and assumed it was an angular bug of some kind.
Do both buttons exhibit this behavior or just the Submit button?
The submit button calls newItem from ng-click, but the name of the function in the js is actually createItem.

Why is this form evaluating to true?

<form name="companyProfileForm" autocomplete="false" novalidate ng-submit="OnSaveCompanyProfile(companyProfileForm.$valid)" ng-controller="companyProfileDataEntryController">
<section ng-hide="!IsCompanyKnown();" class="row">
<div class="small-12 medium-6 large-6 columns">
<!--Industry-->
<section class="row">
<div class="small-12 medium-12 large-12 columns" ng-class="{ 'has-error' : (companyProfileForm.Industry.$invalid && submitted) }">
<div class="form-group">
<label for="Industry">*Industry</label>
<select name="Industry"
ng-model="CompanyProfileModel.IndustryId"
ng-options="item.Id as item.Description for item in IndustryList"
required>
<option value=null>-- select an industry --</option>
</select>
<span class="help-block" ng-show="companyProfileForm.Industry.$invalid && submitted">Please select a value.</span>
</div>
</div>
</section>
</div>
</section>
<button></button>
</form>
No matter what I do this form will evaluate to true. I want it to throw an error that Industry is required. Upon submit it goes to a function that prints to the console the parameter. It prints true every time.
You need to use the AngularJS ng-required directive, not required. Change the select element required to ng-required="true":
<select name="Industry" ng-model="CompanyProfileModel.IndustryId" ng-options="item.Id as item.Description for item in IndustryList" ng-required="true">
<option value=null>-- select an industry --</option>
</select>
Using 'required' on a form element will work in angular so long as your form element has an ng-submit="action()" and a button EXACTLY as follows inside the form:
<button type='submit' ng-click='submit()'>SomeText</button>

How to create contact form in joomla 3

I'm Trying to create custom contact form in Joomla 3 , the reason is I didn't found such big contact form.
Can somebody tell me how to do it ?
html:
<div class="col-lg-12">
<form role="form" method="POST" style="margin-top: 2.7em;" action="">
<div class="row">
<div class="form-group col-lg-4">
<label for="input1">Name</label>
<input type="text" name="contact_name" class="form-control" id="input1">
</div>
<div class="form-group col-lg-4">
<label for="input2">Mail</label>
<input type="email" name="contact_email" class="form-control" id="input2">
</div>
<div class="form-group col-lg-4">
<label for="input3">Phone</label>
<input type="phone" name="contact_phone" class="form-control" id="input3">
</div>
<div class="form-group col-lg-4">
<label for="input1">Dropdown</label>
<select class="form-control" name="bud">
<option value="a">parterowy</option>
<option value="b">piętrowy</option>
<option value="c">bliźniak</option>
<option value="c">mieszkalny</option>
<option value="c">niemieszkalny</option>
</select>
</div>
<div class="form-group col-lg-4">
<label for="input2">Size</label>
<input type="email" name="contact_email" class="form-control" id="input2">
</div>
<div class="form-group col-lg-4">
<label for="input3">Garage</label>
<select class="form-control" name="garaz">
<option value="a">wolnostojący</option>
<option value="b">w budynku</option>
<option value="c">jednostanowiskowy</option>
<option value="c">wielostanowiskowy</option>
</select>
</div>
<div class="clearfix"></div>
<div class="form-group col-lg-12">
<label for="input4">Msg</label>
<textarea name="contact_message" class="form-control" rows="6"id="input4"></textarea>
</div>
<div class="form-group col-lg-12">
<input type="hidden" name="save" value="contact">
<button type="submit" class="btn btn-default">Send</button>
</div>
</div>
</form>
</div>
Fiddle to html
I read that i need to create custom component or rebuild other, which one is better option ?
You could use Chronoforms component to create virtually any form you like.
If you need some very special custom output, you can first use the included form bulider to set up the closest approximation and modify it as you like.
As you have already made the html part, the easier way is to implement your code in a custom module or for a more advanced result in a custom component.
The official joomla way for adding extra fields to contact form is by creting a custom plugin.
If you want a commercial solution (component) I would suggest you to use breezingforms.
Hope this helps

Resources