This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
First here's my code
Ok my problem is That when trying to use the registration form it doesn't call the code.
i have examined this several times and cant seem to find a problem i'm using the login script on the same page and that seems just fine.
login.js
$(function() {
// Expand
$("#open").click(function(){
$("div#panel").slideDown("slow");
});
// Collapse
$("#close").click(function(){
$("div#panel").slideUp("slow");
});
// Change Text
$("#toggle a").click(function () {
$("#toggle a").toggle();
});
// Login proccess Start
$('.error').hide();
$(".bt_login").click(function() {
// validate input
$('.error').hide();
var username = $("input#username").val();
if (username == "") {
$("label#username_error").show();
$("input#username").focus();
return false;
}
var password = $("input#password").val();
if (password == "") {
$("label#password_error").show();
$("input#password").focus();
return false;
}
var rememberMe = $("input#rememberMe").val();
// correct data sent
var dataString = 'username='+ username + '&password=' + password + '&submit=Login' + '&rememberMe=' + rememberMe;
alert (dataString);return false;
$.ajax({
type: "POST",
url: "../../inc/files/login.php",
data: dataString,
success: function() {
return false;
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
$('#login_form').html("<div id='message'></div>");
$('#message').html("<h2>!</h2>")
.append("<p>Error Details; <br /> Status: ", textStatus, " <br /> Error thrown: ", errorThrown,"</p>")
.hide()
.fadeIn(1500, function() {
$('#message').append("<img id='cross' src='images/cross.png' />");
});
return false;;
}
});
});
// End login proccess
//Registration Process start
$("bt_register").click(function() {
// validate inpu
$('.error').hide();
var username2 = $("input#username2").val();
if (username2 == "") {
$("label#username2_error").show();
$("input#username2").focus();
return false;
}
// var re = new RegExp("/[^a-z0-9\-\_\.]+/i");
// if(re.test(username2) = true) {
// $("label#username2_error2").show();
// $("input#username2").focus();
// return false;
// }
var password2 = $("input#password2").val();
if (password2 == "") {
$("label#password2_error").show();
$("input#password2").focus();
return false;
}
var email = $("input#email").val();
if (password == "") {
$("label#email_error").show();
$("input#email").focus();
return false;
}
// correct data sent
var dataString = 'username='+ username2 + '&password=' + password2 + '&submit=Register' + '&email=' + email;
alert (dataString);return false;
$.ajax({
type: "POST",
url: "../../inc/files/login.php",
data: dataString,
success: function() {
return false;
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
$('#reg_form').html("<div id='message'></div>");
$('#message').html("<h2>!</h2>")
.append("<p>Error Details; <br /> Status: ", textStatus, " <br /> Error thrown: ", errorThrown,"</p>")
.hide()
.fadeIn(1500, function() {
$('#message').append("<img id='cross' src='images/cross.png' />");
});
return false;
}
});
});
});
html form calling the Jquery
<div id="reg_form">
<form class="clearfix" action="" >
<h1>Register Here!</h1>
<label class="grey" for="username">Username:</label>
<input class="text-input" type="text" name="username2" id="username2" value="" size="23" />
<label class="error" for="username2" id="usernamename2_error">This field is required.</label>
<label class="error" for="username2" id="usernamename2_error2">Your username contains invalid characters!</label>
<label class="grey" for="email">Email:</label>
<input class="text-input" type="text" name="email" id="email" size="23" />
<label class="error" for="email" id="email_error">This field is required.</label>
<label class="grey" for="password2">Password:</label>
<input class="text-input" type="password" name="password2" id="password2" size="23" />
<label class="error" for="password2" id="password2_error">This field is required.</label>
<input type="submit" name="submit" value="Register" class="bt_register" />
</form>
</div>
Change
$("bt_register").click(function() {
TO
$(".bt_register").click(function(event) {
event.preventDefault();
Second error is if (password == "") { because for .bt_register click event you did not defined password variable.
What you can do is define var password; as global so every click event function can use it.
I have modified your code here is what i did and which is alerting passed string.
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$(function()
{
var password;
$("#open").click(function()
{
$("div#panel").slideDown("slow");
});
$("#close").click(function()
{
$("div#panel").slideUp("slow");
});
$("#toggle a").click(function ()
{
$("#toggle a").toggle();
});
$('.error').hide();
// Start login proccess
$(".bt_login").click(function(event)
{
event.preventDefault();
$('.error').hide();
var username = $("input#username").val();
if (username == "")
{
$("label#username_error").show();
$("input#username").focus();
return false;
}
password = $("input#password").val();
if (password == "")
{
$("label#password_error").show();
$("input#password").focus();
return false;
}
var rememberMe = $("input#rememberMe").val();
var dataString = 'username='+ username + '&password=' + password + '&submit=Login' + '&rememberMe=' + rememberMe;
alert (dataString);return false;
$.ajax(
{
type: "POST",
url: "../../inc/files/login.php",
data: dataString,
success: function()
{
return false;
},
error: function(XMLHttpRequest, textStatus, errorThrown)
{
$('#login_form').html("<div id='message'></div>");
$('#message').html("<h2>!</h2>").append("<p>Error Details; <br /> Status: ", textStatus, " <br /> Error thrown: ", errorThrown,"</p>").hide().fadeIn(1500, function() {
$('#message').append("<img id='cross' src='images/cross.png' />");
});
return false;;
}
});
});
// End login proccess
//Registration Process start
$(".bt_register").click(function(event)
{
event.preventDefault();
// validate inpu
$('.error').hide();
var username2 = $("input#username2").val();
if (username2 == "")
{
$("label#username2_error").show();
$("input#username2").focus();
return false;
}
var password2 = $("input#password2").val();
if (password2 == "")
{
$("label#password2_error").show();
$("input#password2").focus();
return false;
}
var email = $("input#email").val();
if (password == "")
{
$("label#email_error").show();
$("input#email").focus();
return false;
}
// correct data sent
var dataString = 'username='+ username2 + '&password=' + password2 + '&submit=Register' + '&email=' + email;
alert (dataString);return false;
$.ajax(
{
type: "POST",
url: "../../inc/files/login.php",
data: dataString,
success: function()
{
return false;
},
error: function(XMLHttpRequest, textStatus, errorThrown)
{
$('#reg_form').html("<div id='message'></div>");
$('#message').html("<h2>!</h2>").append("<p>Error Details; <br /> Status: ", textStatus, " <br /> Error thrown: ", errorThrown,"</p>").hide().fadeIn(1500, function()
{
$('#message').append("<img id='cross' src='images/cross.png' />");
});
return false;
}
});
});
});
</script>
<div id="reg_form">
<form class="clearfix" action="" >
<h1>Register Here!</h1>
<label class="grey" for="username">Username:</label>
<input class="text-input" type="text" name="username2" id="username2" value="" size="23" />
<label class="error" for="username2" id="usernamename2_error">This field is required.</label>
<label class="error" for="username2" id="usernamename2_error2">Your username contains invalid characters!</label>
<label class="grey" for="email">Email:</label>
<input class="text-input" type="text" name="email" id="email" size="23" />
<label class="error" for="email" id="email_error">This field is required.</label>
<label class="grey" for="password2">Password:</label>
<input class="text-input" type="password" name="password2" id="password2" size="23" />
<label class="error" for="password2" id="password2_error">This field is required.</label>
<input type="submit" name="submit" value="Register" class="bt_register" />
</form>
</div>
Instead i suggest you to do this with submit form:
$("#reg_form").children('form').submit(function (e) {
e.preventDefault(); //<------------stops the submission
// validate inpu
$('.error').hide();
var username2 = $("input#username2").val();
if (username2 == "") {
$("label#username2_error").show();
$("input#username2").focus();
return false;
}
var password2 = $("input#password2").val();
if (password2 == "") {
$("label#password2_error").show();
$("input#password2").focus();
return false;
}
var email = $("input#email").val();
if (password == "") {
$("label#email_error").show();
$("input#email").focus();
return false;
}
// correct data sent
var dataString = $(this).serialize();
alert(dataString);
$.ajax({
type: "POST",
url: "../../inc/files/login.php",
data: dataString,
success: function () {
alert('success.');
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
$('#reg_form').html("<div id='message'></div>");
$('#message').html("<h2>!</h2>")
.append("<p>Error Details; <br /> Status: ", textStatus, " <br /> Error thrown: ", errorThrown, "</p>")
.hide()
.fadeIn(1500, function () {
$('#message').append("<img id='cross' src='images/cross.png' />");
});
return false;
}
});
});
ok
i thik your var dataString is not well formatted
you can try this syntax
data: '{LiveID: "' + Live_ID + '", CategoryID: "' + Category_ID + '"}',
This allowed me to create a label and have it link to a predefined function. Enclude the function within the body of the document and before the label.
<label class="error" for="username2" id="usernamename2_error2">Your username contains invalid characters!
function(open)
Related
I have three google forms on a page. Each form is linked to a tab on a single spreadsheet.
For now I have duplicated the working code from here: https://codepen.io/xergioalex/pen/ZNevvM
A single form was working fine, however now that there are three it no longer functions.
All inputs eg. "entry.472617792" should be correct.
Link to public Spreadsheet.
// Form01
$('#contact-form01').submit(function(event) {
event.preventDefault();
$('#feedback01').html('');
setTimeout(function() {
// Get data
var data = {
'entry.472617792': $('#form-name01').val(),
'entry.898916053': $('#form-phone01').val(),
'entry.1085111698': $('#form-message01').val()
};
// Validate form
var formSuccess = true;
Object.keys(data).forEach(function(key, index) {
if (!data[key]) {
formSuccess = false;
$('#feedback01').html('<label class="text-danger">Please complete all fields</label>');
}
});
if (formSuccess) {
// Send request
$.ajax({
url: 'https://docs.google.com/forms/u/2/d/e/1FAIpQLSfiJghWBgMBn-twEzVfeIWMQhyp_3oFa26r1bdA-A71n_3Enw/formResponse',
type: 'POST',
crossDomain: true,
dataType: "xml",
data: data,
success: function(jqXHR, textStatus, errorThrown) {
console.log('Enter on success');
$('#feedback01').html('<label class="text-success">Message sent!</label>');
},
error: function(jqXHR, textStatus, errorThrown) {
console.log('Enter on error');
$('#feedback01').html('<label class="text-success">Message sent!</label>');
}
});
}
}, 300);
});
// Form02
$('#contact-form02').submit(function(event) {
event.preventDefault();
$('#feedback02').html('');
setTimeout(function() {
// Get data
var data = {
'entry.472617792': $('#form-name02').val(),
'entry.898916053': $('#form-phone02').val(),
'entry.1085111698': $('#form-message02').val()
};
// Validate form
var formSuccess = true;
Object.keys(data).forEach(function(key, index) {
if (!data[key]) {
formSuccess = false;
$('#feedback02').html('<label class="text-danger">Please complete all fields</label>');
}
});
if (formSuccess) {
// Send request
$.ajax({
url: 'https://docs.google.com/forms/u/2/d/e/1FAIpQLSfnPLSloZWtGXTqhexuJsb9LoEA9U8-uYGYj3Ex5SS5Nwty0w/formResponse',
type: 'POST',
crossDomain: true,
dataType: "xml",
data: data,
success: function(jqXHR, textStatus, errorThrown) {
console.log('Enter on success');
$('#feedback02').html('<label class="text-success">Message sent!</label>');
},
error: function(jqXHR, textStatus, errorThrown) {
console.log('Enter on error');
$('#feedback02').html('<label class="text-success">Message sent!</label>');
}
});
}
}, 300);
});
// Form03
$('#contact-form03').submit(function(event) {
event.preventDefault();
$('#feedback03').html('');
setTimeout(function() {
// Get data
var data = {
'entry.472617792': $('#form-name03').val(),
'entry.898916053': $('#form-phone03').val(),
'entry.1085111698': $('#form-message03').val()
};
// Validate form
var formSuccess = true;
Object.keys(data).forEach(function(key, index) {
if (!data[key]) {
formSuccess = false;
$('#feedback03').html('<label class="text-danger">Please complete all fields</label>');
}
});
if (formSuccess) {
// Send request
$.ajax({
url: 'https://docs.google.com/forms/u/2/d/e/1FAIpQLSfK6S-GlcKsq8YCz4OBwlTsf9g8frbGouP4VGkyXiykaH1UMw/formResponse',
type: 'POST',
crossDomain: true,
dataType: "xml",
data: data,
success: function(jqXHR, textStatus, errorThrown) {
console.log('Enter on success');
$('#feedback03').html('<label class="text-success">Message sent!</label>');
},
error: function(jqXHR, textStatus, errorThrown) {
console.log('Enter on error');
$('#feedback03').html('<label class="text-success">Message sent!</label>');
}
});
}
}, 300);
});
.container {padding-bottom:50px;}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!--Form 01-->
<div class="container">
<h2>Form 01</h2>
<form method="post" id="contact-form01">
<input type="text" class="form-control" id="form-name01" placeholder="Name*"><br>
<input type="text" class="form-control" id="form-phone01" placeholder="Phone*"><br>
<textarea type="text" class="form-control" id="form-message01" placeholder="Message*"></textarea><br>
<button type="submit" class="btn btn-default">
Submit
</button>
<div id="feedback01"></div>
</form>
</div>
<!--Form 02-->
<div class="container">
<h2>Form 02</h2>
<form method="post" id="contact-form02">
<input type="text" class="form-control" id="form-name02" placeholder="Name*"><br>
<input type="text" class="form-control" id="form-phone02" placeholder="Phone*"><br>
<textarea type="text" class="form-control" id="form-message02" placeholder="Message*"></textarea><br>
<button type="submit" class="btn btn-default">
Submit
</button>
<div id="feedback02"></div>
</form>
</div>
<!--Form 03-->
<div class="container">
<h2>Form 03</h2>
<form method="post" id="contact-form03">
<input type="text" class="form-control" id="form-name03" placeholder="Name*"><br>
<input type="text" class="form-control" id="form-phone03" placeholder="Phone*"><br>
<textarea type="text" class="form-control" id="form-message03" placeholder="Message*"></textarea><br>
<button type="submit" class="btn btn-default">
Submit
</button>
<div id="feedback03"></div>
</form>
</div>
I am struggling to make it work to pass element id to Jquery from html foreach loop. I have a table and I am getting the details from database. so in each loop we are getting new data for new users. I am using bootstrap switch as seen below :
<form method="post" id="toggleForm">
<fieldset>
<div class="form-group">
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" id="customSwitch1" name='machine_state' status="{{$detail['status']}}">
<input type="hidden" id="id" value="{{$detail['id']}}" >
<label class="custom-control-label" id="statusText" for="customSwitch1"> </label>
<llittle id ="littleupdate"></llittle>
</div>
</div>
</fieldset>
</form>
In the Jquery part we have three functions as shown below:
function putStatus() {
var id = $("#id").val();
$.ajax({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
type: "post",
url: "/admin/check-status",
data: {id : id},
success: function (result) {
if (result == "true") {
$('#customSwitch1').prop('checked', true);
statusText(1);
} else {
$('#customSwitch1').prop('checked', false);
statusText(0);
}
}, error:function (){
}
});
}
function statusText(status_val) {
if (status_val == 1) {
var status_str = "Active";
} else {
var status_str = "Inactive";
}
document.getElementById("statusText").innerText = status_str;
}
function onToggle() {
$('#toggleForm :checkbox').change(function () {
if (this.checked) {
//alert('checked');
updateStatus(1);
// statusText(1);
} else {
//alert('NOT checked');
updateStatus(0);
// statusText(0);
}
});
}
function updateStatus(status_val) {
var id = $('#id').val();
$.ajax({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
type: "POST",
url: "/admin/set-status",
data: {status: status_val, id:id},
success: function (result) {
if(result =="true") {
if(status_val == 1) {
$('#customSwitch').prop('checked', true);
// $("#updatedAt").fadeIn(0).html("<font color='green' font size='2px'> - Updated.. User Activated!</font>").fadeOut(1500);
// $( '#littleupdate').fadeIn(0).html("<font color='green' font size='1px'> Updated.. </font>").fadeOut(1500);
statusText(1);
} else if(status_val == 0){
$('#customSwitch').prop('checked', false);
// $("#updatedAt").fadeIn(0).html("<font color='green' font size='2px'> - Updated.. User Deactivated!</font>").fadeOut(1500);
// $( '#littleupdate').fadeIn(0).html("<font color='green' font size='1px'> Updated.. </font>").fadeOut(1500);
statusText(0);
}
} else {
if(status_val == 1){
$('#customSwitch1').prop('checked', false);
$("#updatedAt").fadeIn(0).html("<font color='red'> - Error while updating!</font>").fadeOut(1500);
} else if(status_val == 0){
$('#customSwitch1').prop('checked', true);
$("#updatedAt").fadeIn(0).html("<font color='red'> - Error while updating!</font>").fadeOut(1500);
}
}
}, error:function (){
}
});
}
$(document).ready(function () {
//Called on page load:
putStatus();
onToggle();
statusText();
});
Html loop as a whole is looking like below:
#foreach($details as $detail)
<tr>
<td>
{{$detail['id']}}
</td>
<td>
{{$detail['name']}}
</td>
<td>
{{$detail['type']}}
</td>
<td>
{{$detail['email']}}
</td>
<td>
<img src="{{asset('/admin/images/avatars/'.$detail['image'])}}">
</td>
<td>
{{$detail['mobile']}}
</td>
<td>
<form method="post" id="toggleForm">
<fieldset>
<div class="form-group">
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" id="customSwitch1" name='machine_state' status="{{$detail['status']}}">
<input type="hidden" id="id" value="{{$detail['id']}}" >
<label class="custom-control-label" id="statusText" for="customSwitch1"> </label>
<llittle id ="littleupdate"></llittle>
</div>
</div>
</fieldset>
</form>
</td>
I really can't figure out the mechanism of passing the function to each loop element, as it only works correctly for the first instance in the table as can be seen in image below. Your help would be highly appreciated.
Because in loop , the id attribute is the same
In loop
<form method="post" id="toggleForm_{{$detail['id']}}">
<fieldset>
<div class="form-group">
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" id="customSwitch_{{$detail['id']}}" name='machine_state' status="{{$detail['status']}}">
<input type="hidden" class="statusForDetail" value="{{$detail['id']}}" >
<label class="custom-control-label" id="statusText_{{$detail['id']}}" for="customSwitch_{{$detail['id']}}"> </label>
<llittle id="littleupdate_{{$detail['id']}}"></llittle>
</div>
</div>
</fieldset>
</form>
function putStatus() {
$(".statusForDetail").each((index, element) => {
let id = $(element).val()
$.ajax({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
type: "post",
url: "/admin/check-status",
data: {id : id},
success: function (result) {
if (result == "true") {
$('#customSwitch_'+id).prop('checked', true);
statusText(1);
} else {
$('#customSwitch_'+id).prop('checked', false);
statusText(0);
}
}, error:function (){
}
});
});
}
The Previous issue of getting status 400 error has been resolved , I am able to retrieve the response as a JSON Object , I am here with attaching the modified code , The received JSON response is being stored in the JSON Object :
response_jsonObj , The output is in this format
0: { id: "value od id", name: "value of name" , field1: "value of field1" , field2: "value of field2" , ...}
0: { id: "value od id", name: "value of name" , field1: "value of field1" , field2: "value of field2" , ...} and so forth, I need to display this in the tabular format , I have followed the examples on stack overflow and am unable to replicate it , Any inputs are welcome .
import React, { Component } from 'react';
import './App.css';
class App extends Component {
constructor() {
super();
this.handleSubmit = this.handleSubmit.bind(this);
this.state = { responsedata:[{"id":"","name":"","field1":"","field2":""}] }
}
handleSubmit(event) {
event.preventDefault();
const form = event.target;
const data = new FormData(form);
const arrayValue = [];
var i = 0;
console.log('Data from Form:',data);
for (let name of data.keys()) {
const input = form.elements[name];
const parserName = input.dataset.parse;
const parsedValue = data.get(name);
console.log('name',name);
console.log('parsedValue',parsedValue);
data.set(name, parsedValue);
arrayValue[i] = parsedValue;
i=i+1;
}
console.log('id:after get',arrayValue[0]);
console.log('field1:after get',arrayValue[2]);
console.log('field7:after get',arrayValue[8]);
var response_data = "";
var response_jsonObj ;
var txt = "";
var req = {"CustomerLookupRequest" : [{
"id":arrayValue[0],
"name": "",
"field1":arrayValue[2],
"field2":"",
"field3":"",
"field4":"",
"field5":"",
"field6":"",
"field7":arrayValue[8],
"field8":"",
"field9":"",
"fied10":"",
"field11":""
}]
};
console.log('req string :' + req);
fetch('API_URL', {
headers: {
'Accept': 'application/json, text/plain, application/xml, */*',
'Content-Type': 'application/json' ,
'Access-Control-Allow-Headers': 'Content-Type',
},
method: 'POST',
body: JSON.stringify(req)}
).then(function(response) {
if (response.status !== 200) {
console.log('Problem in fetching');
return;
}
response.text().then(function(data) {
console.log('Data in Console',data);
response_data = data;
console.log('Response Data',response_data);
response_jsonObj = JSON.parse(response_data);
console.log('Response JSON Object',response_jsonObj);
});
}).catch(error => this.setState({ error }));
}
render() {
return (
<div id = "id1">
<form onSubmit={this.handleSubmit}>
<label htmlFor="id">Enter id</label>
<input id="id" name="id" type="text" />
<label htmlFor="name">Enter Name</label>
<input id="name" name="name" type="text" />
<label htmlFor="Field1">Enter your Field1</label>
<input id="Field1" name="Field1" type="text" />
<label htmlFor="Field2">Enter your Field2</label>
<input id="Field2" name="Field2" type="text" />
<label htmlFor="Field3">Enter your Field3</label>
<input id="Field3" name="Field3" type="text" />
<label htmlFor="Field4">Enter your Field4</label>
<input id="Field4" name="Field4" type="text" />
<label htmlFor="Field5">Enter your Field5</label>
<input id="Field5" name="Field5" type="text" />
<label htmlFor="Field6">Enter your Field6</label>
<input id="Field6" name="Field6" type="text" />
<label htmlFor="Field7">Enter your Field7</label>
<input id="Field7" name="Field7" type="text" />
<label htmlFor="Field8">Enter your Field8</label>
<input id="Field8" name="Field8" type="text" />
<label htmlFor="Field9">Enter your Field9</label>
<input id="Field9" name="Field9" type="text" />
<label htmlFor="Field10">Enter your Field10</label>
<input id="Field10" name="Field10" type="text" />
<label htmlFor="Field11">Enter your Field11</label>
<input id="Field11" name="Field11" type="text" />
<button>Send data!</button>
</form>
</div>
);
}
}
export default App;
I'm not sure your fetch format is correct. Do this way.
fetch(POSTAPIURL, {
method: 'post',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
String1:"xyzabc",
String2:"ABCD"
})
}).then(function(response) {
return response.json();
}).then(function(data) {
console.log(data);
}).catch( err => {
console.log(err);
});
I know this is a common question , but I am facing problem in this. I am unable to refresh by input fields on button click.
When I am clicking button , the information is sent and added up in a list. So whenever I click it the input fields must get cleared/refresh (not page load).
View:
<div class="input-group">
<span class="input-group-addon" id="reg_input">Name</span>
<input type="text" class="form-control" placeholder="Name" ng-model="ff.Name" required>
</div>
<div class="input-group">
<span class="input-group-addon" id="reg_input">Block</span>
<input class="form-control" id="bl" type="text" ng-model="ff.Block" required>
</div>
<div class="input-group">
<input type="text" class="form-control" id="ip" type="text" ng-model="ff.IP" ng-maxlength="2" style="width: 30px" required>
</div>
<a class="btn btn-md btn-primary" ng-click="getClick(ff)">Add</a>
Is there any refresh predefined in bootstrap button ?
EDIT controller:-
$scope.list = {};
$scope.array_of_Names = [];
$scope.getClick= function() {
$scope.master = angular.copy($scope.ff);
$http.post("url", $scope.list).success(function(data) {
$scope.AllData= data;
$scope.addInfo.Segments.push($scope.list);
$scope.ff.Name = "";
$scope.ff.Block= "";
$scope.ff.IP= "";
$scope.array_of_Names.push($scope.list);
console.log("Segment successfully created");
},function (data, status, headers, config) {
// growl.error("Something went wrong");
});
console.log($scope.master);
};
Just Try it!. All property under $scope.ff will be reset.
$scope.ff={};
And you can apply it in your code part like this:
$scope.list = {};
$scope.array_of_Names = [];
$scope.getClick= function() {
$scope.master = angular.copy($scope.ff);
$http.post("url", $scope.list).success(function(data) {
$scope.ff={};
$scope.AllData= data;
$scope.addInfo.Segments.push($scope.list);
$scope.array_of_Names.push($scope.list);
console.log("Segment successfully created");
},function (data, status, headers, config) {
// growl.error("Something went wrong");
});
console.log($scope.master);
};
EDIT:
$scope.getClick= function() {
$scope.master = angular.copy($scope.ff);
$scope.ff = {};
$http.post("url", $scope.list).success(function(data) {
$scope.AllData= data;
$scope.addInfo.Segments.push($scope.list);
$scope.array_of_Names.push($scope.list);
console.log("Segment successfully created");
},function (data, status, headers, config) {
// growl.error("Something went wrong");
}).error(function(err) {
console.log("Error: ", err);
});
console.log($scope.master);
};
Try then instead of success
$scope.getClick = function(ff){
$scope.master = angular.copy($scope.ff);
$http.post("url", $scope.list).then(function(data) {
$scope.AllData= data;
$scope.addInfo.Segments.push($scope.list);
$scope.ff.Name = "";
$scope.ff.Block= "";
$scope.ff.IP= "";
$scope.array_of_Names.push($scope.list);
console.log("Segment successfully created");
},function (data, status, headers, config) {
// growl.error("Something went wrong");
});
console.log($scope.master);
}
I want to Refresh the page after displaying a message or alert saying "Successful" or vice-versa. How can I implement it?
I tried refresing code but it do not display message after that.
HTML CODE:
<div class="row" ng-controller="PublishManifestCtrl">
<div class="col-xs-12 col-md-12">
<div class="widget">
<div class="widget-header bordered-bottom bordered-themeprimary">
<i class="widget-icon fa fa-tasks themeprimary"></i>
<span class="widget-caption themeprimary">Manifest Status</span>
</div>
<div class="widget-body">
<form class="form-bordered" role="form">
<div class="form-group">
<label style="padding-left: 8px;">Manifest was last published to agents on <b>{{manifeststatus.manifestLastPublishedDate}}</b>.</label>
</div>
<div class="form-group">
<label style="padding-left: 8px;">Manifest was last updated by <b> {{manifeststatus.lastUpdatedByUser}} </b> on <b>{{manifeststatus.manifestLastedUpdatedDate}}</b>.</label>
</div>
<div class="form-group">
<div class="col-sm-offset-1">
<button id="PublishButton" class="btn btn-default shiny " ng-disabled="manifeststatus.enablePublishButton" ng-click="Save(manifeststatus)">Publish</button>
</div>
<br/>
<div id="statusDivPublish" ng-show="showstatus">
<alert type="{{alert.type}}">{{alert.msg}}</alert>
</div>
</div>
</form>
</div>
JS Code:
app.controller('PublishManifestCtrl', function ($scope, $rootScope, $http) {
$scope.showstatus = false;
$http({
url: $rootScope.WebApiURL + '/getmanifeststatus',
method:get(),
params: { 'foobar': new Date().getTime() }
}).
success(function (data, status, headers, config) {
var options = { year: "numeric", month: "long", day: "numeric", hour: "numeric", minute: "numeric" };
data.manifestLastedUpdatedDate = (new Date(data.lastUpdatedDateTime)).toLocaleDateString('en-US', options);
data.manifestLastPublishedDate = (new Date(data.lastPublishDateTime)).toLocaleDateString('en-US', options);
var date1 = new Date(data.lastUpdatedDateTime);
var date2 = new Date(data.lastPublishDateTime);
data.enablePublishButton = date2.getTime() > date1.getTime();
$scope.manifeststatus = data;
}).
error(function (data, status, headers, config) {
alert('error' + status);
// log error
});
$scope.Save = function (data) {
debugger;
$http.post($rootScope.WebApiURL + '/updatemanifeststatus');
//refresh
$state.transitionTo($state.current, $stateParams, {
reload: true,
inherit: false,
notify: true
});
$scope.showstatus = true;
$scope.alert = { type: 'success', msg: 'Published Successfully.' };
$(".statusDivPublish").show();
)});
Implementation
$scope.Save = function (data) {
// debugger;
$http.post($rootScope.WebApiURL + '/updatemanifeststatus');
//made change
$scope.manifeststatus = data;
$scope.showstatus = true;
$scope.alert = { type: 'success', msg: 'Published Successfully.' };
$(".statusDivPublish").show();
//refresh
$state.transitionTo($state.current, $stateParams, {
reload: true,
inherit: false,
notify: true
});
}
});
Originally It should be in this way:
in your html
<div>{{date}}</div>
in our angularjs file
$scope.Save = function (data) {
$http.post($rootScope.WebApiURL + '/updatemanifeststatus');
$scope.date = data.date;
//refresh
$scope.showstatus = true;
$scope.alert = { type: 'success', msg: 'Published Successfully.' };
$(".statusDivPublish").show();
$(".statusDivPublish").remove();
)});