When I press Sign In in my autorization it should change the signInValid to true,but unfortunetly only alert working:(
And is it correct to use FOR in angularJS to see is login and pass correct? Or there are some better ways to do it?
Here`s my JS code:
$scope.signInValid = false;
$scope.signIn = function (userDetails) {
for (let i = 0; i < $scope.userlist.length; i++) {
if (userDetails.login == $scope.userlist[i].username && userDetails.password == $scope.userlist[i].password) {
alert('welcome')
$scope.signInValid = true;
}
}
}
Here`s HTML code:
<h1>Permissions allowed: <span style="{{setStyle(signInValid)}}">{{signInValid}}</span></h1>
And if you invert and set the signInValid property to true first ?
if (userDetails.login == $scope.userlist[i].username && userDetails.password == $scope.userlist[i].password) {
$scope.signInValid = true;
alert('welcome');
}
Fixed it by setting controller to body block,my div wasnt inside the controlle scope.Thanks all for answers!
Related
I dont know very well jquery/javascript and I am having problems with the code below.
After the form validation steps, the button is disabled but the form is not submited. Where is wrong?
$(function() {
$('.form_error').hide();
$("#submit_button").click(function() {
var tempo_show = 400
$('.form_error').hide();
var card_name = $("input#card_name").val();
if (card_name == "") {
$("span#validation_card_name").fadeIn(tempo_show);
//alert("Informe o Nome do titula do cartão");
$("input#card_name").focus();
return false;
}
var owner_birthdate = $("input#owner_birthdate").val();
if (owner_birthdate.length < 8) {
$("span#validation_owner_birthdate").fadeIn(tempo_show);
//alert("Informe o Nome do titula do cartão");
$("input#owner_birthdate").focus();
return false;
}
// here is where I can't make work
$(this).html('Processando...');
$(this).attr('disabled', true);
});
});
I think this $("input#card_name").val(); should be this $("#card_name").val();. The reason is you don't need to specify the element type when you want to get them by ID. Make similar changes to the rest of the code as well. Try adding $("#YOURFORMID").submit() at the end.
Try this:
$(function() {
$('.form_error').hide();
$("#submit_button").click(function() {
var tempo_show = 400
$('.form_error').hide();
var card_name = $("#card_name").val();
if (card_name == "") {
$("#validation_card_name").fadeIn(tempo_show);
//alert("Informe o Nome do titula do cartão");
$("#card_name").focus();
return false;
}
var owner_birthdate = $("#owner_birthdate").val();
if (owner_birthdate.length < 8) {
$("#validation_owner_birthdate").fadeIn(tempo_show);
//alert("Informe o Nome do titula do cartão");
$("#owner_birthdate").focus();
return false;
}
// here is where I can't make work
$(this).html('Processando...');
$(this).attr('disabled', true);
$("#YOURFORMID").submit();
});
});
Good day. I have read and done almost all of the solution in the questions but cant seem to solve my problem. As written in my question, in mvc, i am passing a value from controller to view a string and then get by javascript to run a modal if ever a certain condition is met. please help. thanks.
here is the code in my controller:
public ActionResult Series()
{
List<sample> series = db.samples.Where(x => x.status == "False").ToList();
if ( series.Count == 0)
{
ViewBag.Info = "None";
}
else {
ViewBag.Series = series;
ViewBag.Info = "Have";
}
return View();
}
My View:
<input type="text" value="#ViewBag.Info" id="info" name="info" />
My Javascript:
#section Scripts{
<script>
$(window).on('load', function () {
var modelll = document.getElementById("#(ViewBag.Info)").value;
var s_end = document.getElementById("myNumber2").value;
var s_current = document.getElementById("myNumber3").value;
var s_status1 = document.getElementById("status").value;
var s_id1 = parseInt(document.getElementById("myNumber").value);
var s_end2 = parseInt(s_end, 10);
var s_current2 = parseInt(s_current, 10);
var x = parseInt(s_current, 10) + 1;
document.getElementById("item1").value = s_id1;
document.getElementById("item2").value = s_end;
document.getElementById("item3").value = x;
document.getElementById("status2").value = s_status1;
if (modelll === 'Have')
{
if ((s_current2 > s_end2) && (s_current2 != s_end2)) {
$('#myModal').modal({ backdrop: 'static', keyboard: false });
$('#myModal').modal('show');
}
}
else
{
$('#myModal').modal({ backdrop: 'static', keyboard:false });
$('#myModal').modal('show');
}
});
</script>
}
getElementById need an ID but you are passing #ViewBag.Info. change it to :
var modelll = document.getElementById("info").value;
also you are making many extra variables which are not really needed. for example to get what you have in s_current2, you can use
var s_current = parseInt(document.getElementById("myNumber3").value, 10);
no need to create another variable to convert it to integer.
To get the value from textbox
var modelll = document.getElementById("info");
To set the value to textbox
document.getElementById("info").value = var modelll;
you are using #ViewBag.Info instead of element id.
Following line is causing the problem in your code :
var modelll = document.getElementById("#(ViewBag.Info)").value;
// document.getElementById needs Id but you are passing #(ViewBag.Info) which is wrong
var modelll = document.getElementById("info").value; //info id of your textbox
// now check
if (modelll === 'Have')
{ }
else
{ }
I have problem with my textarea.
When I want clear her with ng-click, nothing happens ...
Can you help me ?
This is my code, you can test with Jsfiddle : My app
If you prefer see it here :
HTML :
<div ng-controller="Ctrl1">
<div><textarea id="yourid" ng-model="isWriting" ng-change="writeEvent(isWriting)"></textarea>
<span ng-if="displaySend == 1">Yann says :</span> {{isWriting}}
<p ng-click="sendYaah(isWriting); isWriting == ''">YAH!</p>
</div>
JS :
$scope.writeEvent = function(isWriting) {
$scope.imWriting = isWriting;
var empty = "";
if ($scope.imWriting != empty){
$scope.displaySend = 1;
// $scope.waitResponse = true;
} else {
$scope.displaySend = 0;
// $scope.waitResponse = false;
}
}
Thank for help !
Change ==(equality operator) to =(assignment operator) in ng-click
isWriting == ''
to
isWriting = ''
Forked Fiddle
I am a newbie in angularjs.
I was stuck on a code and wanted some help.
I am having a controller called watchlist controller in which I am getting the data which is to be displayed in the watchlist.
However I want to display the data only once the watchlist tab is clicked.
This is the Html code :-
<div class='watchlist' >
<button class='btn' id="watchList" ng-click="fetchUserWatchlist()" watchlist-popover ng-controller="WatchlistController">
<i class="hidden-tablet hidden-phone"></i>
<span class = 'mywatchlist'>My Watchlist</span>
<div class = 'watchlist-spinner ' ></div>
</button>
</div>
My controller(watchlist):-
$scope.fetchUserWatchlist = function(pageno,callback){
$scope.isLoading = true;
$rootScope.isrequest = true;
userAPI.myWatchlist({userid:$rootScope.getUser().userid,pageno:pageno}, function(r) {
if (_.isNull(r.watchlistdata)) {
if(typeof callback == 'function'){
callback();
}
if(pageno == 1){
$scope.watchlist = [];
$scope.watchlistCount = 0;
}
if (!$rootScope.apiCalled && pageno == 1){
if(!_.isUndefined($rootScope.watchlistClicked) && $rootScope.watchlistClicked){
$rootScope.$broadcast("watchlist::click");
imageLoadingIndicator();
}
$rootScope.apiCalled = true;
}
return false;
}
if (!_.isUndefined(r.watchlistdata.watchlist)){
var rawData = [];
var tempWatchlist = $scope.watchlist;
if (_.isArray(r.watchlistdata.watchlist))
rawData = r.watchlistdata.watchlist;
else
rawData = [r.watchlistdata.watchlist];
if (pageno == 1) {
$scope.watchlistCount = parseInt(rawData[0].totalcount);
}
if ($scope.watchlist.length == 0 || ($scope.watchlist.length > 0 && pageno == 1))
$scope.watchlist = rawData;
else
_.each(sortByDate(rawData),function(item){
if (! _.some(tempWatchlist,function(existingItem){ return existingItem.programmeid == item.programmeid; }))
{
$scope.watchlist.push(item);
}
});
$scope.watchlistPage += 1;
$timeout(function(){
if (!$rootScope.apiCalled && pageno == 1){
if(!_.isUndefined($rootScope.watchlistClicked) && $rootScope.watchlistClicked){
$rootScope.$broadcast("watchlist::click");
imageLoadingIndicator();
}
$rootScope.apiCalled = true;
}
},1);
$rootScope.isrequest = false;
if(typeof callback == 'function'){
callback();
}
}else
$rootScope.end = true;
});
};
So basically I want to implement ng-click on the controller but here in the above scenario it does not help..The data is called before the button is clicked.
Please help me with this
ng-click will work using the scope:
ng-click="executeThis()"
will look in the $scope for a variable named 'executeThis'. F.e.:
$scope.executeThis = function(){
// Do stuff you want
};
So when you click the element that has this ng-click attribute, the executeThis function on the scope will be executed. In this function you should do whatever you want to do. To display something when you click it, you could use the function to set a variable on the scope to true and then use ng-show to display what you want to display.
HTML:
<div ng-show="varX">someDiv</div>
JS inside controller:
$scope.varX = false;
So whenever you set this variable to true, your element should be shown.
However, I do suggest following some tutorials since I suspect you don't yet grasp how angular works.. Understanding how the fundamentals of angular work is definitely necessary if you want to develop an app.
try
<button class='btn' id="watchList" ng-click="myClickFunction()" watchlist-popover ng-controller="WatchlistController">
The best way to learn (IMHO) is documentation :-)
I'm not too good on the whole JavaScript (I can do some basic validations) but this isn't my zone
I've got a piece of code below that I'm trying to understand what it does, I can read any code and understand a few parts, but this just stumped me.
Here:
function tm_search_click() {
if (document.getElementById('tm').value == 'Enter your trademark') {
document.getElementById('tm').style.backgroundColor = '#fcc';
return false;
} else {
window.location = '?tm=' + escape(document.getElementById('tm').value);
return true;
}
}
function qs(a) {
a = a.replace(/[[]/, "\[").replace(/[]]/, "\]");
var b = "[\?&]" + a + "=([^&#]*)";
var c = new RegExp(b);
var d = c.exec(window.location.href);
return d == null ? "" : decodeURIComponent(d[1]).replace(/+/g, " ")
}
if (qs("tm") != "") {
tm_trademark = document.getElementById("tm").value = unescape(qs("tm"));
tm_partner = "migu2008";
tm_frame_width = 630;
tm_frame_height = "auto";
tm_trademark_country_code = "GB";
tm_css_url = "http://remarqueble.com/api/theme/search_corporate.css";
document.getElementById("tmLoading").style.display = "block";
tm_on_search_result = function () {
document.getElementById("tmLoading").style.display = "none";
document.getElementById("tmLoaded").style.display = "block"
}
} else {
tm_search_method = "none"
}
That is all of it without the <script> tags.
Could I also edit this code so that it searches are made based on what option the user inputs?
I think it works like this (assuming that this is in tags inside html page)
Page loads.
The script checks if URL has 'tm' parameter. If it has, then it sets bunch of tm_.. parameters and callback function. I don't know how they are used.
User clicks something that triggers the tm_search_click
Script sets new URL for the page and browser starts loading that
Goto step 1.