Alright this problem has been driving me a little crazy.
I have a checkbox on my form that looks like this:
<%=Html.CheckBox("Agreement", false)%>Yes, I agree to the terms
And then I have a js file that is loaded into the browser after jquery and jquery.validate are loaded that looks like this:
$.validator.setDefaults({
submitHandler: function() { alert("submitted!"); }
});
$().ready(function() {
// validate signup form on keyup and submit
$("#campForm").validate({
rules: {
Agreement: "required"
},
messages: {
Agreement: "Please accept our policy"
}
});
});
So reading the documentation this should work but it never does. What am I doing wrong?
I thought the syntax was supposed to be:
rules: {
Agreement: {required: true}
}
I could be wrong though. This is just off the top of my head.
Are you returning validate on the form submit? Just a guess...
Related
My current URL for searches is this one:
https://example.com/search/key/seach_word_here
JSON-LD
<script type='application/ld+json'>
[
{
"#context":"http:\/\/schema.org",
"#type":"WebSite",
"#id":"#website",
"url":"https://example.com",
"name":"Example",
"potentialAction":{
"#type":"SearchAction",
"target":"https:https://example.com/search/key/{search_term_string}",
"query-input":"required name=search_term_string"
}
},
{
"#context":"http:\/\/schema.org",
"#type":"Organization",
"url": "https://example.com",
"name": "Example",
"logo":"https://example.com/img/logo.png",
"#id":"#organization",
"sameAs": ["https://www.facebook.com/example"]
}
]
</script>
As you can see I'm using a friendly URL on the target.
I have seen people using a query string on the URL like this:
https://example.com/?search={search_term_string}
I did not see people using a friendly URL on the target. It's not allowed?
And at https://developers.google.com/search/docs/data-types/sitelinks-searchbox it says:
Verify your search engine implementation by copying the WebSite.potentialAction.target URL from your structured data, replacing search_term_string with a test query, and browsing to that URL in a web browser. For example, if your website is example.com, and you want to test the query "kittens", you would browse to https://www.example.com/search/?q={kittens}.
I tested this url https://example.com/search/hey/{search_word_here} and I got a 404 not found, but this URL worked: https://example.com/?p=search&tp=key&word={search_word_here}.
So my question is: Can I use a friendly URL on the target? And the code on my snippet is correct?
Of course you have to use the URL that works.
Google will use the target URL for their Sitelink Searchbox, so that users can search on Google’s SERP and end up on your internal SERP. If you specify a target URL that leads to 404 pages, having this feature makes no sense, and Google would have no interest to enable it for your results.
If that URL happens to be friendly (e.g., without a query component), so be it.
Agree with above solution from #unor, now answering about you code correction
Please check the target url in posted JSON-LD:-
"target":"https:https://example.com/search/key/{search_term_string}",
Remove the double https:
Also in case of JSON-LD: you cannot map name value to /{search_term_string}
A correct way is always like this:-
<script type="application/ld+json">
{
"#context": "http://schema.org",
"#type": "WebSite",
"url": "[website url]",
"potentialAction": {
"#type": "SearchAction",
"target": "[website search url]={search_term}",
"query-input": "required name=search_term"
}
}
</script>
Microdata:-
<div itemscope itemtype="http://schema.org/WebSite">
<meta itemprop="url" content="[website url]"/>
<form itemprop="potentialAction" itemscope itemtype="http://schema.org/SearchAction">
<meta itemprop="target" content="[website search url]={search_term}"/>
<input itemprop="query-input" type="text" name="search_term">
<input type="submit">
</form>
</div>
We have an electron crypto app that signs transactions (among other things).
We want other websites to have the ability to have a button that opens that electron app, pre-filled with some params (the transaction information).
flow is:
user clicks "make transaction" on some-crypto-site.com
electron app opens up with pre-filled params
user clicks "sign transaction" in electron app
electron app does stuff behind the scenes
electron app closes and sends a message to some-crypto-site.com
This could be done at runtime, or install time.
What I tried (linux, chrome)
calling app.setAsDefaultProtocolClient with the code of this gist, which is basically:
app.setAsDefaultProtocolClient("my-app")
But after I put my-app://foo?bar=baz in chrome browser, I get the following popup, and pressing open-xdg does nothing (other than dismissing the popup)
I looked into
Electron protocol api which seems to handle in-app protocols only
webtorrent .desktop file This might be the way to go, I'm just not sure how to go about it.
Maybe there's a way to do so at install time through electron builder?
Thanks in advance for the help, I have no idea how to proceed here!
Resources that might be useful
github repo with mac+window example
github comment for linux
github comment for linux 2
SO answer for all 3 OSs
SO windows answer
npm package for windows registery
SO mac answer
SO linux answer
microsoft docs for windows
windows article
github comment for windows
github comment for mac
info.plst for mac
old repo for mac and win
Since this may be relevant to what I’m doing at work, I decided to give it a go.
I’ve only tested this on OSX though!
I looked at the documentation for app.setAsDefaultProtocolClient and it says this:
Note: On macOS, you can only register protocols that have been added to your app's info.plist, which can not be modified at runtime. You can however change the file with a simple text editor or script during build time. Please refer to Apple's documentation for details.
These protocols can be defined when packaging your app with electron-builder. See build:
{
"name": "foobar",
"version": "1.0.0",
"main": "main.js",
"scripts": {
"start": "electron .",
"dist": "electron-builder"
},
"devDependencies": {
"electron": "^3.0.7",
"electron-builder": "^20.38.2"
},
"dependencies": {},
"build": {
"appId": "foobar.id",
"mac": {
"category": "foo.bar.category"
},
"protocols": {
"name": "foobar-protocol",
"schemes": [
"foobar"
]
}
}
}
In your main thread:
const {app, BrowserWindow} = require('electron');
let mainWindow;
function createWindow () {
mainWindow = new BrowserWindow({width: 800, height: 600})
mainWindow.loadFile('index.html');
}
app.on('ready', createWindow);
var link;
// This will catch clicks on links such as open in foobar
app.on('open-url', function (event, data) {
event.preventDefault();
link = data;
});
app.setAsDefaultProtocolClient('foobar');
// Export so you can access it from the renderer thread
module.exports.getLink = () => link;
In your renderer thread:
Notice the use of the remote API to access the getLink function exported in the main thread
<!DOCTYPE html>
<html>
<body>
<p>Received this data <input id="data"/></p>
<script>
const {getLink} = require('electron').remote.require('./main.js');
document.querySelector('#data').value = getLink();
</script>
</body>
</html>
Example
open in foobar
This also allows you to launch from the command line:
open "foobar://xyz=1"
How do you get back to the original caller?
I suppose that when you launch the app you could include the caller url:
<a href="foobar://abc=1&caller=example.com”>open in foobar</a>
When your electron app finishes processing data, it would simply ping back that url
Credits
Most of my findings are based on:
From this GitHub issue
And the excellent work from #oikonomopo
All little bit different from above.
open-url fires before the ready event so you can store it in a variable and use within the widow did-finish-load.
let link;
let mainWindow;
function createWindow() {
mainWindow = new BrowserWindow({
width: 1280,
height: 720,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
});
mainWindow.openDevTools();
mainWindow.setContentProtection(true);
mainWindow.loadFile('index.html');
mainWindow.webContents.on("did-finish-load", function() {
mainWindow.webContents.send('link', link);
});
}
app.on('ready', createWindow);
// This will catch clicks on links such as open in foobar
app.on('open-url', function(event, url) {
link = url;
if (mainWindow?.webContents) {
mainWindow.webContents.send('link', link);
}
});
app.setAsDefaultProtocolClient('protocols');
You can then use the value in your render html like this.
<!DOCTYPE html>
<html>
<head></head>
<body>
<script>
const ipc = require("electron").ipcRenderer;
ipc.on("link", function (event, url) {
console.log(url);
console.log(parseQuery(decodeURI(url)));
});
function parseQuery(queryString) {
queryString = queryString.substring(queryString.indexOf("://") + 3);
var query = {};
var pairs = (queryString[0] === "?" ? queryString.substr(1) : queryString).split("&");
for (var i = 0; i < pairs.length; i++) {
var pair = pairs[i].split("=");
query[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1] || "");
}
return query;
}
</script>
</body>
</html>
I am using Jquery dialog box for Confirmation and alert purposes...
This is my code...
$( "#dialog-confirm" ).dialog({
resizable: false,
modal: true,
buttons: {
"Yes": function() {
$( this ).dialog( "close" );
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
I am not getting any error. So far it's working fine, but it seems the performance is a bit slow. My question is if any performance issue will come in the future? If any performance issue does occur, how would I avoid that?
Please help me with this and correct me if I am wrong in anything.
It is very unlikely that this snippet is slow now or in the future - have you tried timing it? It is possible that you have some other code in the page that is being triggered by this call but we'd need to see the whole page to be able to investigate this.
Firebug has a decent JavaScript profiler to help you find performance issues.
I have used a tutorial http://www.devcurry.com/2010/06/load-page-dynamically-inside-jquery-ui.html to dynammically load an aspx page into a jquery ui dialog without using an iframe
eg.
$(function() {
$('<div>').dialog({
autoOpen: true,
modal: true,
open: function() {
$(this).load('Example.aspx');
},
height: 400,
width: 400,
title: 'Dynamically Loaded Page'
});
When I debugged this page it just loading a blank dialog box with none of the content in even though the page has content. I have written it with the paths
eg $(this).load('/Home/Example.aspx');
I have even added in a function to check if it is loading
eg $(this).load('/Home/Example.aspx', function(){alert(Load Successful);}); which does return true YET still no content in the dialog
I am using Jquery 1.3.2 an ui 1.7.3 with ASP.Net Mvc
I know there are lots of questions/answers on this topic on stackoverflow but none of them seem to be successfully answering my problem and as these questions seem a year old not sure whether someone will get back to me asap.
Any ideas on showing the content in the dialog
Thank you
Just a thought, try changing your selector to
$('<div></div>').dialog({
Also the example you cited is using jquery 1.4.2 and jquery ui 1.8.1,
can you upgrade?
Edit:
You could also try it this way.
$(function() {
$('<div></div>').load('Example.aspx', {},
function(data) {})
.dialog(
{
autoOpen: true,
modal: true,
height: 400,
width: 400,
title: 'Dynamically Loaded Page'
}).dialog('open');
});
Note I haven't tested this, but its the way I do it. Hopefully you get the idea.
The answer is...
$(function() {
$('<div></div>').hide().load('Home/Example #content_form', function() {
$(this).dialog({
autoOpen: true,
modal: true,
height: 400,
width: 400,
title: 'Dynamically Loaded Page'
})
})
With Example.aspx having a tag with ID = content_form
as the title says....
this is what I have tried but not working
$('#uxReferralAssessmentDetailsDialog').dialog({
autoOpen: false,
modal: true,
width: 400,
title: "Referral Assessment",
buttons: { "Save":{ id: 'uxbtnSaveAssessment', click:othis.OnAssessmentSave}, "Cancel": function() { $(this).dialog("close"); } }
});
I am using selenium and instead of the horrid xpath I want to use the id of each element to simplify the xpath
any ideas welcome
If you are having a hard time determining id as and other things that are being added to the html page by javascript on the fly. Try using a development tool for web browsers like firebug which is an addon for firefox:
See link for firebug addon for more information:
https://addons.mozilla.org/en-US/firefox/addon/1843