SAPUI5 sam.m.Input.submit() does not work - model-view-controller

Currently I want to create a function to handle when user press Enter on Input field (sap.m.Input). I found this suitable function submit() in the API.
However it didn't work, I tried but nothing happen. I pressed enter but it does not call the responding function.
Here my code:
App.view.xml
<mvc:View controllerName="Test.controller.App" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m">
<App>
<pages>
<Page title="{i18n>title}">
<content>
<Input submit='onSubmit'/>
</content>
</Page>
</pages>
</App>
</mvc:View>
App.controller.js:
sap.ui.define([
"sap/ui/core/mvc/Controller"
], function(Controller) {
"use strict";
return Controller.extend("Test.controller.App", {
onSubmit: function(oEvent){
console.log("Submitted");
}
});
});
I pressed enter but nothing showed in the console.
I'm looking for help from your expert experience. Is the submit() function does not work anymore? Is there another function to solve my question?

First of all submit is not a function, it's an event.
This event is fired when user presses the Enter key on the input.
So, function to be called when event is fired should be specified as this event's value in view.
View code:
<Input submit='onSubmit'/>
Controller code:
onSubmit: function(oEvent) {
console.log("Submitted");
}

Related

checkbox onCLick function using AJAX

My question is simple, I have a contact form with a checkbox in it. What I want is when the user clicks the checkbox, a message to appear on the side. What I will add in future is, when a second checkbox is clicked to change the message, but first I would like to fix this. I saw some similar questions asked, but I still couldnt do it. The code is:
The checkbox inside the form:
<input type="checkbox" onclick="check(this);" />
This is still in the same file, contact.php
<script type="text/javascript">
function check(cb)
{
if(cb.checked)
{
$.getScript("clickCheckbox.php");
}
}
and another php which is supposed to be called after a click: clickCheckbox.php
<?php
header("Content-type: text/javascript");
echo 'alert("Clicked!");';
?>
What am I not doing right? I am a begginer, so I will apriciate every comment and advice. Thank you!

How can I change the style of a div on return from a form submit action in Razor MVC3?

I have a Razor/ASP/MVC3 web application with a form and a Submit button, which results in some action on the server and then posts back to the form. There is often some delay, and it's important that users know they should wait for it to complete and confirm before closing the page or doing other things on the site, because it seems users are doing that and sometimes their work has not been processed when they assume it has.
So, I added a "Saving, Please Wait..." spinner in a hidden Div that becomes visible when they press the Submit button, which works very nicely, but I haven't been able to find a way to get the Div re-hidden when the action is complete.
My spinner Div is:
<div id="hahuloading" runat="server">
<div id="hahuloadingcontent">
<p id="hahuloadingspinner">
Saving, Please Wait...<br />
<img src="../../Content/Images/progSpin.gif" />
</p>
</div>
</div>
Its CSS is:
#hahuloading
{
display:none;
background:rgba(255,255,255,0.8);
z-index:1000;
}
I get the "please wait" spinner to appear in a JS method for the visible button, which calls the actual submit button like this:
$(document).ready(function () {
$("#submitVisibleButton").click(function () {
$(this).prop('disabled', true);
$("#myUserMessage").html("Saving...");
$("#myUserMessage").show();
$("#hahuloading").show();
document.getElementById("submitHiddenButton").click();
});
});
And my view model code gets called, does things, and returns a string which sets the usermessage content which shows up fine, but when I tried doing some code in examples I saw such as:
// Re-hide the spinner:
Response.write (hahuloading.Attributes.Add("style", "visibility:hiddden"));
It tells me "hahuloading does not exist in the current context".
Is there some way I am supposed to define a variable in the view model which will correspond to the Div in a way that I can set its visibility back from the server's action handler?
Or, can I make the div display conditional on some value, in a way that will work when the page returns from the action?
Or, in any way, could anyone help me figure out how to get my div re-hidden after the server action completes?
Thanks!
Is this done with ajax? I would assume so because the page is not being redirected. Try this:
$(document).ready(function () {
$("#submitVisibleButton").click(function () {
$(this).prop('disabled', true);
$("#myUserMessage").html("Saving...");
$("#myUserMessage").show();
$("#hahuloading").show();
document.getElementById("submitHiddenButton").click();
});
$("#hahuloading").ajaxStop(function () {
$(this).hide();
});
});
As an aside, you no longer need runat=server.

remoteFunction grails

Hi I have a textArea and I have added a onkeyup event to it. When the event is triggered I want to update another element, by taking the input of the textArea and manipulating it in a javascript function. Here is my textArea tag:
<g:textArea name="translation" id="2" cols="40" rows="5" value="${domainInstance?.translation}"
onkeyup="${remoteFunction(
controller: 'domain',
action: 'ajaxChangeTranslation',
params:'\'text=\'+this.value',
onComplete:'updateEntry(e)')}" />
and here is my stub javascript function:
<g:javascript>
function updateEntry(e){
alert("Hi");
}
</g:javascript>
My javascript function is never getting called. I never see the alert when I type something into the textArea. If I place an alert outside of the function the alert shows up. Why is my javascript function not getting called. When I ran it with the chrome debugger I didn't get any errors.
Try this:
<g:textArea name="translation" id="2" cols="40" rows="5" value="${domainInstance?.translation}"
onkeyup="${remoteFunction(
controller: 'domain',
action: 'ajaxChangeTranslation',
params:'\'text=\'+this.value',
onComplete :'updateEntry(XMLHttpRequest,textStatus)')}" />

MVC button click to action [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Mvc Html.ActionButton
With ASP.NET MVC 3 I know how to create a link to an action method very easily but what I'd like to know is how do you make a button (when clicked) call a particular action method?
Sachin,
If you're using jquery (which you don't mention but I'll show as it's fairly standard with mvc), you'd do the following:
$('#buttonId').click(function(){
document.location = '#Url.Action("MyAction","MyController")';
});
of course, you'd probably want to use ajax, but this is a basic example.
You could use an html <form>:
#using (Html.BeginForm("SomeAction", "SomeController", FormMethod.Get))
{
<input type="submit" value="Click me" />
}
How do you do it?
The same way you would if not using MVC.
<INPUT TYPE="BUTTON" VALUE="Home Page" ONCLICK="window.location.href='/Controller/Action'">
As well as Darin's answer about using a form GET method, you can also call javascript functions that will then in turn call an action.
You can intercept the button click event when clicked and run your own code. That code can call an action asynchronously using Ajax or just simply navigate to an action method
Here's sample javascript that intercepts the button click event
$(document).ready(function () {
myButton.onclick = function (event) {
// in here you can call an ajax method or just navigate to an action
return false;
}
// or using jQuery
$('#myButton').click(function (e) {
// do whatever here
e.preventDefault;
});
});
Or you can intercept a button that has an href attribute
$(function () {
$("#myButton").click(function () {
var href = $(this).attr("href");
var route = href + "?paramName=" + $('#SomeValue').val();
$(this).attr("href", route);
});
});
This adds parameter information that you may have stored in another input on the page and appends it to the Url and then navigates to the action

Simple textbox validation - display message is nothing is entered

I'm pretty new to this so here goes...
I'm using Visual Studio 05 (C#) and in my program I have a textbox and a submit button. The user enters an email address and results are then displayed from the database (this works) using an ASP gridview control.
What I am after is a simple piece of validation that if nothing has been entered into the textbox, display a message (or a popup) to say that something needs to be entered.
Many thanks!
Use the RequiredFieldValidator.
<asp:RequiredFieldValidator ID="Id1" runat="server" ErrorMessage="*" ValidationGroup="1" ControlToValidate="txt_Test" />
<asp:TextBox runat="server" ID="txt_Test" />
You can use the CustomValidator for displaying a popup, just provide it your own javascript function.
On the client side this bit of jQuery code could help
$(function(){
$('#id_of_form').submit(function(e){
if($.trim($('#id_of_textbox').val()) === '') {
alert('Textbox cannot be empty');
return false;
}
return true;
});
});
If you're using WinForms, you can do the following:
if (String.IsNullOrEmpty(txt_Test.Text.Trim()))
{
MessageBox.Show("You must enter something.");
}

Resources