Wednesday 13 June 2018

Validating the fields in Touch UI Dialog

Steps given below are for restricting the user to enter less than ten characters in one of the text field of Touch UI dialog. In this process, we will create a validator and we will register that validator correspond to that text field. 

1. Create a component with touch UI dialog with at least one text field. Here in this example we are adding validation to 'First Name' text field. Where author is not allowed to enter less than 10 characters in text field.


2.  Create a client library folder for that component add properties(categories and dependencies) as given below.



3.  Create JS(nt:folder) folder inside clientlibs folder and add  javascript file (validations.js) in JS folder.

4. Create js.txt parallel to JS folder and  make an entry of 'validations.js' there.

5. Open validation.js file and copy paste the below given code. This js code works as validator for the text field.

(function($, Granite) {
    "use strict";



    /**
     * Validator for First Name length.
     */
    $(window).adaptTo("foundation-registry").register("foundation.validation.validator",{
        selector: '[data-validation="namelength"]',
        validate: function(el) {
            var valid = el.value;

            var strLength= valid.length;
            if (strLength<10) {
                return Granite.I18n.get("Length should be greater than 10");
            }
        }
    });


})(Granite.$, Granite);

6. 'namelength' used as a selector here for the registered validator. And we will hook our registered validator with this selector property only.
7. validate function will execute the logic for validation. Here its checking the length of the value entered in dialog First Name field.
8. Now to hook our registered validator with our touch UI dialog text field .We will add property 'validation' with its value 'namelength'. This is will hook our text field validation with  our registered validator.



9. Now try less than 10 char in First Name field. Error message is displayed.  





10. Check out the below link for more explanation about the same.



Sunday 3 June 2018

Configuring Dispatcher in Local Enviornment

                                       

  • Set up AEM Author(localhost:4502) and Publish(localhost:4503) instances in local.
  • Download (httpd-2.2.25-win32-x86-no_ssl.msi ) Apache server from http://archive.apache.org/dist/httpd/binaries/win32/
  • Install the Apache Server. Steps given below. 
  1. After downloading it, double click on 'msi' file to install the server on your local machine.
  2. Just before the finish step change the directory for installation to “C:\Apache2”. We can keep any path for installation of Apache and later can make the changes in config files.The configuration files 'httpd' and 'dispatcher.any' provided here having path set to “C:\Apache2”, so if you directly copy paste this then there is no need to change the paths in file.
  3. To check Apache web server installed properly go to /bin folder and run the below commands
                                           httpd -k install
                                               httpd – k start
    4. If you don’t get any error. Open the browser hit localhost:8080. It will display a “It Works” message. Apache web server successfully installed now.


  • Unzip the folder and copy ‘disp_apache2.2.dll’ and move it here(C:\Apache2\modules) 

  •   Download the httpd and dispatcher.any file and paste it in /conf folder of our Apache server and replace the existing httpd. Link given below.               

                                       Dispatcher.any
                                  httpd.conf


  • All the changes already done to httpd and dispatcher file. To learn more about this please refer to this link.
                      http://www.aemcq5tutorials.com/tutorials/set-up-dispatcher-in-aem/