Unbind datepicker focus event - datepicker

I use next script to focus on input when validation failes (in ASP .NET MVC)
$(function () {
$(".datepicker").datepicker();
var inp = $('.input-validation-error:first').get(0);
if (inp) {
inp.focus();
}
});
But when my input has datepicker it activated and hide error message.
So I need not to show datepicker when I focus on input with this script

Try putting the datepicker() call after you give it focus. Example:
$(function () {
var inp = $('.input-validation-error:first').get(0);
if (inp) {
inp.focus();
}
$(".datepicker").datepicker();
});

$(function () {
$(".datepicker").datepicker();
var inp = $('.input-validation-error:first').get(0);
if (inp) {
inp.focus();
inp.unbind().datepicker(); // this is works
}
});

Related

Not able to initilize the JS view in openui5

Not able to initilize the below JS view in index page. Could you please help me?
I m getting this error msg "Uncaught (in promise) TypeError: t.createContent is not a function"
Plunker link:
https://plnkr.co/edit/7v0CN93aDrAOY9WqU269?p=preview
app.view.js:
sap.ui.jsview("app",{
getControllerName:function(){
return "app";
},
createContent:function(oContoller){
var oButton = new sap.m.Button(this.createId("helloButton"),{
text:"Click Me"
});
return oButton;
}
});
change the view code like this
sap.ui.jsview("view.js.app", {
getControllerName: function() {
return "view.js.app";
},
createContent: function(oContoller) {
var oButton = new sap.m.Button(this.createId("helloButton"), {
text: "Click Me"
});
return oButton;
}
});
Also add a controller file app.controller.js and paste below code.
sap.ui.controller("view.js.app", {
onInit: function() {
}
});
You are specifying the resourceroots as "view.js" in the index file.
So while instantiating use below code
var view = sap.ui.view({
id:"idApp1",
type:sap.ui.core.mvc.ViewType.JS,
viewName:"view.js.app"
});
And in the view add these changes,
sap.ui.jsview("view.js.app",{
getControllerName:function(){
return "view.js.app";
},
createContent:function(oContoller){
var oButton = new sap.m.Button(this.createId("helloButton"),{
text:"Click Me"
});
return oButton;
}
});
And add one controller file named app as below,
sap.ui.define(["sap/ui/core/mvc/Controller"],
function (Controller) {
"use strict";
return Controller.extend("view.js.app", {
});
});
Here is the working link.

html2canvas - the screenshotted canvas is always empty/blank

I have a div that i want to screenshot and save,
here is my code
function _download(uri, filename)
{
var el = $('.sf-download-button');
if (el.length)
{
var link = document.createElement('a');
if (typeof link.download === 'string')
{
link.href = uri;
link.download = filename;
document.body.appendChild(link);
//simulate click // this causes page to download an empty html file not sure why
link.click();
//remove the link when done
document.body.removeChild(link);
}
else
{
window.open(uri);
}
}
}
function _save()
{
window.takeScreenShot = function ()
{
var a =document.getElementById("my-div");
html2canvas(document.getElementById("the-div-that-i-want-to-screenshot"), {
onrendered: function (canvas)
{
document.body.appendChild(canvas);
a.append(canvas);
},
width: 220,
height: 310
});
};
$("#btnSave2").click(function ()
{
html2canvas(document.getElementById("data"), {
onrendered: function (canvas)
{
_download_card(canvas.toDataURL(), 'save.png');
}
});
});
}
This is the code i got it from web and added some of my own stuff.code was working i believe but right now, when I click on the button show me the image, it creates the image i can see it but it is just blank.
I tried every possible code combination from jsfiddle and all that and couldn't get anything different as a result.
What could be going wrong here?
I solved the problem by simply changing the browser,
It was not working with Chrome but works perfectly on Mozilla.
Also i changed the code to this,
$("#btnSave").click(function() {
html2canvas($("#card"), {
onrendered: function(canvas) {
theCanvas = canvas;
document.body.appendChild(canvas);
// Convert and download as image
$("#img-out").append(canvas);
// Clean up
//document.body.removeChild(canvas);
}
});
});
Works perfect on Mozilla only.

afterEach happening before it

I'm trying to use protractor to make e2e tests for one of our pages.
The pages are run in an iframe of a surrounding system.
So to be able to test my page I have to do all the things before "it ('Overview opened...". I'm not saying I have to do them in the way I have done. If there is a better way, please tell me.
Now my problem is that "errandClose is run before the tests in "Overview opened".
Have I done something wrong or misunderstood how protractor works.
describe('toplevel test', function() {
var login = new loginPage();
var role = new roleSelectionPage();
var errand = new overViewAndErrand(login.getBaseUrl());
beforeEach(function() {
login.getPage(); //Goes to login page and logs in
});
it('should log in', function () {
expect(element(by.model("therole")).isDisplayed());
describe('Select role', function() {
beforeEach(function () {
role.selectRole(); //Selects role on page after login and ends up at next page
});
it('Role selected', function() {
expect(element(by.css('a[href*="/OverviewNext"]')) !== undefined);
describe('Open overview', function() {
beforeAll(function() {
errand.open('name of errand'); //Selects errand and clicks on button, iframe i opened
});
afterEach(function() {
errand.close(); // Leaves the iframe and clicks on remove errand
});
it ('Overview opened', function() {
describe('Test form', function() {
browser.sleep(5000);
it ('test', function() {
browser.sleep(500);
element(by.model("modelvalue")).sendKeys('Ture Trana').then(function() {console.log('Ture Trana')});
});
});
});
});
});
});
});
});
As a response to the flat question.
How I would like to be able to run my tests is something like this
login.getPage();
role.select('role1');
errand.create();
begin
test 1
...
test n
end
errand.save();
role.select(role 2);
errand.open(previous errand);
begin
test 1
...
test n
end
login.logout();
Where all the selectRole, createErrand, openErrand involves going to at least one page and clicking on some buttons and selecting in lists.
You shouldn't nest describe() within it().
You should close this test before you start a new one
Example: This should be closed before you start a new describe.
it('Role selected', function() {
expect(element(by.css('a[href*="/OverviewNext"]')) !== undefined);
Here is an example with nested describes, that works for me.
describe('overview page', () => {
let hostUrl = configMock[0].response.data.URL;
beforeAll(() => {
//do magic
});
describe('all statement cards', () => {
beforeAll(() => {
browser.get(`${hostUrl}/z/y/1/g`);
browser.waitForAngular();
});
describe('Campaign overview', () => {
beforeEach(() => {
//before each magic
});
it('has correct data for Delivered', () => {
expect(delivered.getText()).toEqual('1.6k');
});
});
});
});
Starting from this, I think you can adapt it to your needs.

Tinymce auto spellcheck, without clicking button

Is it possible to set turn the default spell checker on by default. Without clicking the button in the toolbar each time?
I am using the default browser spell checker functionality in the browser.
setup: function (ed) {
ed.addCommand('mceSpellCheckRuntime', function() {
t = ed.plugins.spellchecker;
if (t.mceSpellCheckRuntimeTimer) {
window.clearTimeout(t.mceSpellCheckRuntimeTimer);
}
t.mceSpellCheckRuntimeTimer = window.setTimeout(function() {
t._done();
t._sendRPC('checkWords', [t.selectedLang, t._getWords()], function(r) {
if (r.length > 0) {
t.active = 1;
t._markWords(r);
ed.nodeChanged();
}
});
}, 3000); //3 seconds
});
ed.onInit.add(function(ed){
ed.pasteAsPlainText = true;
ed.execCommand('mceSpellCheckRuntime');
});
ed.onKeyUp.add(function(ed, e) {
ed.execCommand('mceSpellCheckRuntime');
});
},
Its quiet possible........:)
Try the below code.......
ed.onInit.add(function(ed, e) {
setTimeout(function () {
tinyMCE.activeEditor.controlManager.setActive('spellchecker', true); tinymce.execCommand('mceSpellCheck', true);
}, 1);
});
Nope, this is not possible due to the fact that there are so many possibilities of using a spellchecker in tinymce. The user may however define on which events the spellchecker should check (that's what you already did).
Working solution for TinyMCE 3
Create a helper function to improve UX:
function delay(fn, ms) {
let timer = 0
return function(...args) {
clearTimeout(timer)
timer = setTimeout(fn.bind(this, ...args), ms || 0)
}
}
Register a new command within TinyMCE Spell Checker plugin:
ed.addCommand('mceSpellCheckAuto', function() {
if (t.active) {
t._removeWords();
ed.nodeChanged();
t._sendRPC('checkWords', [t.selectedLang, t._getWords()], function(r) {
if (r.length > 0) {
t._markWords(r);
ed.nodeChanged();
}
});
}
});
Call your new command from a keyPress event:
ed.onKeyPress.add(delay(function() {
tinymce.execCommand('mceSpellCheckAuto', true);
}, 500));

ASP.NET MVC2 - hook into client side validation

I want to trigger some custom code when the client side errors are updated using ASP.NET MVC2 client side validation. I've tracked down this function which I want to hook into:
Sys.Mvc.FormContext.prototype = {
// ...
_displayError: function Sys_Mvc_FormContext$_displayError() {
if (this._validationSummaryElement) {
if (this._validationSummaryULElement) {
Sys.Mvc._validationUtil.removeAllChildren(this._validationSummaryULElement);
for (var i = 0; i < this._errors.length; i++) {
var liElement = document.createElement('li');
Sys.Mvc._validationUtil.setInnerText(liElement, this._errors[i]);
this._validationSummaryULElement.appendChild(liElement);
}
}
Sys.UI.DomElement.removeCssClass(this._validationSummaryElement, Sys.Mvc.FormContext._validationSummaryValidCss);
Sys.UI.DomElement.addCssClass(this._validationSummaryElement, Sys.Mvc.FormContext._validationSummaryErrorCss);
}
},
// ...
}
How can I override this function such that my code can
call the original function
then do some other work
Found it.
<script type="text/javascript">
$(function () {
var old_displayError = Sys.Mvc.FormContext.prototype._displayError;
Sys.Mvc.FormContext.prototype._displayError = function () {
old_displayError.apply(this);
// do other stuff here
}
});
</script>
I'm not used to overriding prototype functions, so I was stumped for a bit.