Showing posts with label Jquery. Show all posts
Showing posts with label Jquery. Show all posts

Wednesday, 10 August 2016

Yii2 from events


In Yii2, below are the form events which we can make use it on front end / client side .

  • beforeValidate,
  • afterValidate,
  •  beforeValidateAttribute,
  • afterValidateAttribute,
  • beforeSubmit,
  •  ajaxBeforeSend,
  • ajaxComplete

Example usage:

$("#FORM-ID").on("afterValidate", function (event, messages) {

    // Now you can work with messages by accessing messages variable
 var attributes = $(this).data().attributes; // to get the list of attributes
    that has been passed in attributes property

  var settings = $(this).data().settings; // to get the settings

});

Friday, 25 September 2015

Prevent Form Submission When User Presses the Enter key / Move to next textbox when user presses enter key


 When we filling out the web forms, if we hit the Enter key accidentally, then the form will submit, it makes us frustrating every time.

To prevent this you can use the code below. Instead of submitting, it actually focus / moves to next input boxes when we press Enter key.

$('body').on('keydown', 'input, select, textarea', function(e) {
    var self = $(this)
            , form = self.parents('form:eq(0)')
            , focusable
            , next
            ;
    if (e.keyCode == 13) {
        focusable = form.find('input,a,select,textarea').filter(':visible');
        next = focusable.eq(focusable.index(this) + 1);
        //  console.log(next.attr('type'));
        if (next.length && (next.attr('type') != 'button')) {
            next.focus();
        } else {
            form.submit();
        }
        return false;
    }
});


Monday, 17 March 2014

Yii CGridView Update onkeyup

By default Yii filters the table in cgridview, when a user entering data on search textfield and press Enter key or clicking oustside the grid.
I had a strange situation, i want to apply filter on keyup in cgridview for all pages,

Below is the code to apply filter on keyup in  yii cgridview.

    $(function() {
        $('body').on('keyup', '.filters > td > input', function() {
           
            var focusedId = $(document.activeElement).attr('id');
            var grid_id = $('#' + focusedId + '.form').closest("div").attr('id');
           
            $('#' + grid_id).yiiGridView('update', {
                data: $(this).serialize(),
                complete: function(jqXHR, status) {
                   
                    if (status == 'success') {
                        var tmpStr = $('#' + focusedId + '.form').val();
                        $('#' + focusedId + '.form').focus();
                        $('#' + focusedId + '.form').val('');
                        $('#' + focusedId + '.form').val(tmpStr);
                    }
                   
                }
            });
            return false;
        });

    });

Saturday, 2 November 2013

Simple FAQ System Using Php


This is a basic and simple faq like Q&A application developed using php and Codeigniter.

For design twitter bootstrap is used.

Features Included, below are some,

Admin can Manage
1) Users
2) Question categories
3) User posted questions and answers
4) Users

User can
1) Ask a question
2) Post an answer to question others posted.
3) also add an comment to answer.
4) View the list of question and answers posted by him

General
1) Only logged in user can post a question or answer.
2) Pagination included.

This is only a minimal version not yet a completed version.
You can download it from here,  FAQ System Using Php

Friday, 24 May 2013

Install Laravel 4 on Ubuntu


Recently i willing to learn laravel framework because of its rich features towards web development and that borrows a lot from Rails.In previous i have used the CodeIgniter for my projects.

This post is mainly for beginners, To Install laravel 4 on ubuntu 12.04

Installing Composer:

To install composer via terminal , type the command

# curl -sS https://getcomposer.org/installer | php

Move the composer to usr/local/bin to access composer globally

# mv composer.phar /usr/local/bin/composer
check if the composer is available globally by simply type
#  composer

Installing Laravel:

To install laravel via Git Clone repository first you have to install Git on your machine , if Git is installed in your machine then clone Laravel git repository as

# git clone https://github.com/laravel/laravel.git /opt/lampp/htdocs/lara_test1
 here lara_test1 our newly created project directory for installing laravel , To view the files inside the newly created project folder
#  cd  /opt/lampp/htdocs/lara_test1
#  ls
 To install composer to our project directory
#  composer install
while installing composer if the error thrown such as 
               Laravel requires the Mcrypt PHP extension.
 then you have to install the mycript library , for that simply use
# sudo apt-get install php5-mcrypt
and after that again re-install composer , it may fix issues.

And finally  open your web browser and simply go to
  http://localhost/lara_test1/public/
 Also , dont forget to change the persmission of folders within app/storage .
 

 Every thing goes fine, you welcome with laravel's  default message with Logo.


You have arrived.