#1 2017-02-22 16:31:43

Antonio.Cambule
Member
Registered: 2017-02-19
Posts: 38

[solved]: Howto integrage Validate EAN JS-Code

Here is a small Javascript Validation for EAN Checksum

var checkSum = ean.split('').reduce(function(p,v,i) {
  return i % 2 == 0 ? p + 1 * v : p + 3 * v;
}, 0);

if (checkSum % 10 != 0) {
  alert('error');
}

I have an existing ABScript to validate all fields of an form in a view.
How can i integerate it, and instead of throwing an alert write a message into an variable

thanks and regards
Antonio

Last edited by Antonio.Cambule (2017-02-23 09:15:02)

Offline

#2 2017-02-22 16:38:14

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,660
Website

Re: [solved]: Howto integrage Validate EAN JS-Code

Hello Antonio,

First of all, the concept of "forms" doesn't exists in App Builder. We place inputs around views and then can use AB actions to validate that inputs before send it to the server or whatever other use (remember always we send something to the server the user input must be validated in both the client side and the server side too).

Said that, maybe you no need the above Javascript code. However, if you need that Javascript code, certainly you can use it in whatever place, since we can place pure Javascript code between the "StartJS" and "EndJS" actions in any code block or just add the Javascript inside an external file using the app's file manager to do that.

If what you wanted right now is to access app's variables from Javascript code, as well to set app's variables from Javascript code, please, take a look at this program's help tutorial. Here are some examples from that refered tutorial:

// Set one of our app variables
window.App.RootScope.MyVar = 'New value';

// Give the content of an app variable
alert(window.App.RootScope.MyVar);

// Call one of our app user function
window.App.Scope.MyFunc();
// Call the NewView1 Button1 control Click event
window.App.NewView1.Scope.Button1Click();

// Call the NewView1 Input1 control Change event
window.App.NewView1.Scope.Input1Change();

Please, Antonio, let me know if you have any further question or if you continue needing help to integrate the above Javascript code into your application.

P.S. Another possible way to integrate Javascript code in our apps is to use the app's functions. We can add any number of Javascript functions (and also AB Script functions) to our applications, in addition to place the Javascript code between the "StartJS" and "EndJS" actions or use the app's files manager to add some Javascript file.

Offline

#3 2017-02-22 17:24:56

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,660
Website

Re: [solved]: Howto integrage Validate EAN JS-Code

Hello Antonio,

I decide to write a little sample over the code you shown above in your first post. Please, take a look at this sample application. They contains just one of the possible ways to do the trick and hope they can give some at least some idea.

Offline

Board footer

Powered by FluxBB


Copyright ©2018 DecSoft. All rights reserved.