Skip to content

Commit 42bae2c

Browse files
Gourav DwivediGourav Dwivedi
authored andcommitted
added validation
1 parent 9dadd33 commit 42bae2c

File tree

4 files changed

+74
-2
lines changed

4 files changed

+74
-2
lines changed

src/css/main.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,22 @@ ul.nav .nav-link.active:hover {
128128
margin:0 auto;
129129
}
130130

131+
.error {
132+
width: 100%;
133+
padding: 0;
134+
margin: 0%;
135+
font-size: 80%;
136+
color: #900;
137+
border-radius: 0 0 5px 5px;
138+
box-sizing: border-box;
139+
font-style: italic;
140+
font-weight: bold;
141+
}
142+
143+
.error.active {
144+
padding: 0.3em;
145+
}
146+
131147
/* .mdl-layout__header-row {
132148
padding: 0px 0px 0px 80px;
133149
margin: 0 0 0 0;

src/js/components/logic/lib/app.common.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,23 @@ function ShowElementByClassName(className) {
4040
}
4141
}
4242

43+
function IsValidUrl(url)
44+
{
45+
var pattern = new RegExp('^(https?:\\/\\/)?'+ // protocol
46+
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.?)+[a-z]{2,}|'+ // domain name
47+
'((\\d{1,3}\\.){3}\\d{1,3}))'+ // ip (v4) address
48+
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ //port
49+
'(\\?[;&a-z\\d%_.~+=-]*)?'+ // query string
50+
'(\\#[-a-z\\d_]*)?$','i');
51+
return pattern.test(url);
52+
}
53+
4354
export {
4455
ContentType,
4556
AppEvents,
4657
EnableElementByClassName,
4758
DisableElementByClassName,
4859
HideElementByClassName,
49-
ShowElementByClassName
60+
ShowElementByClassName,
61+
IsValidUrl
5062
};

src/js/components/srform.component.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class SrFormComponent extends HTMLElement {
3737
<label for="inputUrl" class="col-sm-2 col-form-label">Hub Address</label>
3838
<div class="col-sm-8">
3939
<input type="text" class="form-control inputUrl" id="inputUrl" placeholder="Url" value="https://localhost:5001/Test/Hub">
40+
<span class="error" aria-live="polite"><span>
4041
</div>
4142
4243
<div class="col-sm-1 checkbox-container float-left" id="logger-chk-container">
@@ -110,6 +111,7 @@ class SrFormComponent extends HTMLElement {
110111
<label for="inputServerMethod" class="col-sm-2 col-form-label">Server Method</label>
111112
<div class="col-sm-10 offset-sm-2">
112113
<input type="text" class="form-control" id="inputServerMethod" placeholder="Server Method Name">
114+
<span class="error" aria-live="polite"><span>
113115
</div>
114116
</div>
115117
<div class="form-group row onconnect scale-in-ver-top">

src/js/components/srform.js

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,44 @@ export function connectToServer(url) {
290290
start();
291291
}
292292

293+
function UrlValidation() {
294+
const urlElement = document.getElementById("inputUrl");
295+
const errorElement = urlElement.nextElementSibling;
296+
297+
if (AppCommon.IsValidUrl(urlElement.value)) {
298+
errorElement.innerText = "";
299+
errorElement.className = "error";
300+
return true;
301+
} else {
302+
errorElement.innerText = "Invalid Url";
303+
errorElement.className = 'error active';
304+
return false;
305+
}
306+
}
307+
308+
function TextboxValidation(element, errorMessage) {
309+
const errorElement = element.nextElementSibling;
310+
311+
if(!!element.value) {
312+
errorElement.innerText = "";
313+
errorElement.className = "error";
314+
return true;
315+
} else {
316+
errorElement.innerText = errorMessage;
317+
errorElement.className = 'error active';
318+
return false;
319+
}
320+
}
321+
322+
293323
export function OnConnect() {
294324

325+
//Add validation
326+
debugger;
327+
if(!UrlValidation()) {
328+
return;
329+
}
330+
295331
var isAdvanceView = !window.appLogic.GetCurrentView();
296332
if (isAdvanceView) {
297333
SetConnectionProtocol();
@@ -374,7 +410,13 @@ export function Disconnect() {
374410

375411
export function SendPayload() {
376412

377-
var methodName = document.getElementById("inputServerMethod").value;
413+
const methodNameElement = document.getElementById("inputServerMethod");
414+
var methodName = methodNameElement.value;
415+
debugger;
416+
if(!TextboxValidation(methodNameElement, "Please enter the Hub method name")) {
417+
return false;
418+
}
419+
378420
var methodArguments = new Array();
379421

380422
methodArguments = ReadAndFormatArguments();

0 commit comments

Comments
 (0)