Remove content from input - dynamic

can someone help me out with this script. I am trying to do a Formular for submit a recipe.
I want to do a dynamic ingredient formular, where i can add and remove ingredients.
Unfortunately it doesn´t work as I want. My removing function is always removing the first ingredient. How can I remove the the igredient I want to.
Here is my code so far:
function copy(objButton)
{
if(objButton.parentNode)
{
hinzufg=objButton.parentNode.cloneNode(true);
objButton.form.appendChild(hinzufg);
for(j=0;j<objButton.form.lastChild.childNodes.length;++j)
{
if(objButton.form.lastChild.childNodes[j].type=='text')
{
objButton.form.lastChild.childNodes[j].value='';
break;
}
}
}
}
function remove(objButton)
{
var entf = document.getElementById('ingredients');
entf.parentNode.removeChild(entf);
}
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Recipe</title>
</head>
<form action="">
<h2>Recipes</h2>
<strong>Name</strong> <br />
<input type="text" size="50" > <br /><br />
<strong>Ingredients</strong> <br />
<div id="ingredients">
<input type="text" id="AmountIngredients" name="zutatMenge1[]"> ...
<input type ="text" id="zutat" name="firstIngredient[]">
<input type="button" value="+" onclick="copy(this)">
<input type="button" value="X" onclick="remove(this)">
</div>
</form>
<body>
</body>
</html>

Related

controller not sending to view .net core

controller not sending to view . I m trying to send request from controller to view , but its not redirecting . controller always redirect to index page. when i summit the form . its always redirecting same index page ,
controller not sending to view .controller not sending to view
My controller is sending to another view. but its not working .
public IActionResult userLogin([FromBody] Users user)
{
string apiUrl = "https://localhost:44331/api/ProcessAPI";
var input = new
{
email = user.email,
password = user.password
};
string inputJson = (new JavaScriptSerializer()).Serialize(input);
WebClient client = new WebClient();
client.Headers["Content-type"] = "application/json";
// client.Encoding = Encoding.UTF8;
string json = client.UploadString(apiUrl + "/userLogin", inputJson);
// List<Users> customers = (new JavaScriptSerializer()).Deserialize<List<Users>>(json);
user = JsonConvert.DeserializeObject<Users>(json);
return View();
}
and the view page is
#addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
#model myproject.Models.Users
#{
Layout = null;
}
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Inventory Management System</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
#* <link rel="stylesheet" type="text/css" href="./includes/style.css">*#
#*<script type="text/javascript" rel="stylesheet" src="~/js/main.js"></script>*#
</head>
<body>
<div class="overlay"><div class="loader"></div></div>
<!-- Navbar -->
<br /><br />
<div class="container">
<div class="alert alert-success alert-dismissible fade show" role="alert">
#*<?php echo $_GET["msg"]; ?>*#
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
#*<?php
}
?>*#
<div class="card mx-auto" style="width: 20rem;">
<img class="card-img-top mx-auto" style="width:60%;" src="./images/login.png" alt="Login Icon">
<div class="card-body">
<form id="form_login" >
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
#*<input asp-for="Name" type="text" class="form-control" id="name" required />*#
<input asp-for="email" type="email" class="form-control" id="log_email" placeholder="Enter email">
<small id="e_error" class="form-text text-muted">We'll never share your email with anyone else.</small>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input type="password" class="form-control" name="log_password" asp-for="password" id="log_password" placeholder="Password">
<small id="p_error" class="form-text text-muted"></small>
</div>
<button type="submit" class="btn btn-primary"><i class="fa fa-lock"> </i>Login</button>
<span>Register</span>
</form>
</div>
<div class="card-footer">Forget Password ?</div>
</div>
</div>
<input type="text" id="txtName" />
<input type="button" id="btnGet" value="Get Current Time" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("#form_login").on("submit", function () {
var data = {
email: $("#log_email").val(),
password: $("#log_password").val(),
// Phone: $("#phone").val()
}
// data: $("#form_login").serialize(),
// var data = $("#form_login").serialize();
console.log(data);
$.ajax({
type: 'POST',
url: '/Process/userLogin',
// window.location.href = '#Url.Action("Process", "Dashboard")';
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(data),
success: function (result) {
alert('Successfully received Data ');
console.log(result);
window.location.href = "Process/Dashboard";
// window.location.href = '#Url.Content("~/User/Home")';
// window.location.href = '#Url.Action("Process", "Dashboard")';
// window.location.href = DOMAIN + "/dashboard.php";
},
error: function () {
alert('Failed to receive the Data');
console.log('Failed ');
}
})
})
});
</script>
</body>
</html>
From your code, since you want to use JQuery Ajax to submit the form data to the action method, in the form submit event, you should use the event.preventDefault() to prevent the form submit action, then you can use JQuery Ajax to submit the form.
Second, does the Index page is the Process/Dashboard page? From your code, we can see in the Ajax success function, you will use the window.location.href to change the request URL, you can change the redirect page from here.

Using both .isDisplayed and .isEnabled?

Intro: I'm making automated tests with appium and I'm fairly new to it.
Newbie question: Is there any point making double assertions for elements using is.Displayed and .isEnabled?
Assertion .isEnabled means that the element is not disabled, to clarify this here is sample code:
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
Enabled: <input type="text" name="fname"><br>
Disabled: <input type="text" name="lname" disabled><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
First input is enabled and second is disabled, but both of them are displayed. But it could be also like this:
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
Not displayed and enabled: <input type="text" name="fname" style = "display: none"><br>
Displayed and enabled: <input type="text" name="fname" style = "display: inline-block"><br>
Not displayed and disabled: <input type="text" name="lname" disabled style = "display: none"><br>
Displayed and disabled: <input type="text" name="lname" disabled style = "display: inline-block"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
Therefore there are different assertions for Selenium for different test cases. If you want a combination of both .isDisplayed and .isEnabled, use .elementToBeClickable. More information in documentation(JAVA)

Unable to use vanilla JS for AWS Cognito, and get AmazonCognitoIdentity is not defined

I follow the instructions from https://github.com/aws/aws-amplify/tree/master/packages/amazon-cognito-identity-js
Here is my html code:
<html>
<head>
<title>Testing AWS Cognito</title>
<script src="/js/aws/aws-cognito-sdk.js"></script>
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.211.1.min.js"></script>
</head>
<body>
<div>
<input type="text" id="email" name="email" placeholder="email"> <br/>
<input type="text" id="username" name="username" placeholder="username"><br/>
<input type="text" id="phone" name="phone" placeholder="phone"><br/>
<input type="text" id="password" name="password" placeholder="password"><br/>
<button id="signup" onClick="register()" >Register</button>
</div>
<script>
const register = function() {
console.log("onclick loading now");
var CognitoUserPool = AmazonCognitoIdentity.CognitoUserPool;
}
</script>
</body>
</html>
But when I run it, it gives me:
"signup_aws_test.html:32 Uncaught ReferenceError:
AmazonCognitoIdentity is not defined"
I am very sure both files are loaded before I click the button.
in the aws-cognito-sdk.js, I can see that AmazonCognitoIdentity exists and exports. It doesn't seems like it is in the global namespace though.
Do i need to run something else to "Load" it?
Problem solved.
The file name MUST BE
"amazon-cognito-identity.min.js"
although the content the same, the filename matters.
Once I change it to amazon-cognito-identity.min.js, it works.

Yodlee FastLink "An error occurred while processing the request or session is invalid"

I am working on implementing a FastLink2.0 Integration for aggregation in my application. I saw from this post that the interface needs to be called from an HTML form and not just a simple REST GET request.
I was able to get a simple html page to work and redirect to FastLink, but when I put the page into an iframe (as the documentation recommends), it says "An error occurred while processing the request or session is invalid"
<iframe src="fastlink.html"></iframe>
fastlink.html:
<html>
<head>
</head>
<body>
<div class='center processText'>Processing...</div>
<div style="visibility: hidden">
<form action='https://node.developer.yodlee.com/authenticate/restserver/' method='post' id='rsessionPost'>
RSession : <input type='text' name='rsession' placeholder='rsession'
value='<--user token-->'
id='rsession'/><br/>
FinappId : <input type='text' name='app' placeholder='FinappId' value='10003600' id='finappId'/><br/>
Redirect : <input type='text' name='redirectReq' placeholder='true/false' value='true'/><br/>
Token : <input type='text' name='token' placeholder='token'
value='<--authenticated token-->' id='token'/><br/>
Extra Params : <input type='text' name='extraParams' placeholer='Extra Params' value=''
id='extraParams'/><br/></form>
</div>
<script>document.getElementById('rsessionPost').submit();</script>
</body>
</html>
Anyone figure this out? Thanks in advance!
Please follow the steps-
Here is the simple example of how to invoke fastlink in an iframe:
In post.html
<div class='center processText'>Processing...</div>
<div>
<form action='https://node.developer.yodlee.com/authenticate/restserver/' method='post' id='rsessionPost'> RSession :
<input type='text' name='rsession' placeholder='rsession' value='08062013_0:829d770b5c7d29e300a7dabc42108383ecac552de57a9706ed4077c98acde1e29e874e676651813a95543b8fb5e2d5face054f300a03b34e7105976867dde3' id='rsession'/>
<br/> FinappId :
<input type='text' name='app' placeholder='FinappId' value='10003600' id='finappId'/>
<br/> Redirect :
<input type='text' name='redirectReq' placeholder='true/false' value='true'/>
<br/> Token :
<input type='text' name='token' placeholder='token' value='7346ddfb28f1eef2acdc4943695680337a3e5ea2ae9bb88c35d0ed58c702b6' id='token'/>
<br/> Extra Params :
<input type='text' name='extraParams' placeholer='Extra Params' value='' id='extraParams'/>
<br/>
</form>
</div>
<script>document.getElementById('rsessionPost').submit();
</script>
Then invoking this in iframe:
In test.html:
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<iframe src="post.html"></iframe>
</body>
</html>
Hope this helps.
Regards,
Krithik

PhoneGap WcfService

I have a wcf service calling from mobile platfrom. When i call wcf from browser in mobile device it works.Then i convert my html to an application using phone. But this time , i can not call the wcf service. Any ideas?
Here is my html ;
<title>Mobilizm</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="css/Mobilizm.css" rel="stylesheet" />
<link href="css/jquery.mobile.structure-1.3.2.min.css" rel="stylesheet" />
<script src="js/JSON.js"></script>
<script src="js/jquery.js"></script>
<script src="js/jquery.mobile-1.3.2.js"></script>
<script>
$(document).on("pageinit", function (event) {
$('#save').click(function () {
debugger;
var typesArray = new Array();
var myType = new Object();
myType.FirstName = $("#name").val();
myType.LastName = $("#surname").val();
myType.EMailAddress1 = $("#email").val();
myType.MobilePhone = $("#cellphone").val();
typesArray.push(myType);
$.support.cors = true;
$.getJSON("http://xxxxx/Mobile/MobilizmService.svc/CreateCustomer?callback=?", { customers: JSON.stringify(typesArray), origin: 167440003, status: 167440001 })
.done(function (json) {
alert("ok");
})
.fail(function (jqxhr, textStatus, error) {
alert("false");
});
</script>
</head>
<body>
<div data-role="page">
<div data-theme="d" data-role="header">
<h3>Yeni Kullanıcıgg</h3>
</div>
<div data-role="content">
<div data-role="fieldcontain">
<label for="name">Ad:</label>
<input type="text" name="name" id="name" value="" data-mini="true" />
</div>
<div data-role="fieldcontain">
<label for="surname">Soyadı:</label>
<input type="text" name="surname" id="surname" value="" data-mini="true" />
</div>
<div data-role="fieldcontain">
<label for="email">E-Posta:</label>
<input type="text" name="email" id="email" value="" data-mini="true" />
</div>
<div data-role="fieldcontain">
<label for="cellphone">Cep Telefonu:</label>
<input type="text" name="cellphone" id="cellphone" value="" data-mini="true" />
</div>
<input data-theme="d" type="button" value="Kaydet" id="save" />
</div>
<div data-theme="d" data-role="footer">
<h3>Yeni Kullanıcı</h3>
</div>
</div>
After several hours searching , ı solved the problem. You have to add this tag to your config.xml file. Your origin is where you host your webservice.
<access origin="xxx" subdomains="true" />
Try my code:
var serviceUrl = 'http://' + _SERVER_ADDRESS + '/RestService.svc/' + method;
var jsonCallbackMethod = 'spycallback493285721';
$.ajax({
type : "GET",
url : serviceUrl,
jsonpCallback : jsonCallbackMethod,
data : params,
dataType : 'jsonp',
timeout : 11*1000 // Necessary in order to detect not found(404) error
})