Thursday 29 October 2015

MULTIPLE AUTOCOMPLETE IN CODEIGNTER

today i review my project then i found bugs i don't know why my autocomplete doesn't work well, so i fixed from here

so i fix from that tutorial cause that tutorial doesn't give you right autocomplete.

he just select wll data from table without spesific search so here is database acctually same but it's oke

DATABASSE please copy one by one
 CREATE TABLE `tb_kotaindonesia` (  
  `id` int(3) NOT NULL AUTO_INCREMENT,  
  `nama_kota` varchar(50) DEFAULT NULL,  
  `ibu_kota` varchar(50) DEFAULT NULL,  
  `keterangan` text,  
  PRIMARY KEY (`id`)  
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1  
 insert into `tb_kotaindonesia` (`id`, `nama_kota`, `ibu_kota`, `keterangan`) values('1','Medan','Medan','Kota medan adalah ibukota Provinsi Sumatera Utara');  
 insert into `tb_kotaindonesia` (`id`, `nama_kota`, `ibu_kota`, `keterangan`) values('2','Tapanuli Utara','Tarutung','Tapanuli Utara atau sering disebut TAPUT adalah sebuah tempat sejuk');  
 insert into `tb_kotaindonesia` (`id`, `nama_kota`, `ibu_kota`, `keterangan`) values('3','Jakarta','Jakarta','Jakarta Megapolitan Ibukota Negara Republik Indonesia');  
 insert into `tb_kotaindonesia` (`id`, `nama_kota`, `ibu_kota`, `keterangan`) values('4','Padang','Padang','Padang adalah tempat wisata jam gadang, disana terdapat jembatan yang membelah sungai musi');  
 insert into `tb_kotaindonesia` (`id`, `nama_kota`, `ibu_kota`, `keterangan`) values('5','Deliserdang','Lubuk Pakam','Sebuah kota sebelum medan yang kita pijak pertama sekali jika lewat udara (Bandara Kualanamu).');  


Here is my controller, there is diffrent here please see
 $q = strtolower($_GET['term']);  
if refrensi above he didn't tell spesific data in table he just select all woithout key and where clasue in model,
 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');  
 class Kota extends CI_Controller  
 {  
   public function __construct() {  
     parent::__construct();  
     $this->load->model('mkota'); //load model mkota yang berada di folder model  
     $this->load->helper(array('url')); //load helper url  
   }  
   public function index()  
   {  
     $data['titel']='Multiple Output Autocomplete Jquery UI + CodeIgniter'; //varibel title  
     $this->load->view('vkota',$data); //tampilan awal ketika controller kota di akses  
   }  
   public function get_allkota() {  
     $q = strtolower($_GET['term']);  
     $query = $this->mkota->get_allkota($q); //query model  
     $kota    = array();  
     foreach ($query as $d) {  
       $kota[]   = array(  
         'label' => $d->nama_kota, //variabel array yg dibawa ke label ketikan kunci  
         'nama' => $d->nama_kota , //variabel yg dibawa ke id nama  
         'ibukota' => $d->ibu_kota, //variabel yang dibawa ke id ibukota  
         'keterangan' => $d->keterangan //variabel yang dibawa ke id keterangan  
       );  
     }  
     echo json_encode($kota);   //data array yang telah kota deklarasikan dibawa menggunakan json  
   }  
 }  

Model here is i give where clause so you can spesific select table in autocomplete
 <?php  
 class Mkota extends CI_Model {  
   function __construct() {  
     parent::__construct();  
   }  
   function get_allkota($kode) {  
     $this->db->like('nama_kota', $kode);  
     $res = $this->db->get('tb_kotaindonesia');  
     if ($res->num_rows() > 0) {   
       return $res->result();  
     }  
   }  
 }  
 ?>  
Hope you understand lah what i mean here, thanks for visiting me ! file can download right here Note : Please provide file in view if possible just use cdn cause i take in my project

Wednesday 28 October 2015

how detect modal bootsrap will open or close by clicking href

Hello guys, now i will give short tutorial about detect modal open or not, cause sometime programmers need this way to thorw variable inside modal or anything else based on your need it,

Here is my demo Chech This out

Here js detect modal open
  $('#myModal').on('shown.bs.modal', function(event) {  
  alert('modal open baby');  
 });  

Here href to open modal
 <button class="btn btn-info btn-lg" data-target="#myModal" data-toggle="modal" type="button">Open Modal</button>  

Here cancel button in the top
 
 <button aria-hidden="true" class="close" data-dismiss="modal" id="cancel" type="button">×</button>  
 Here cancel button in the bottom  
  <div class="modal-footer">  
 <button class="btn btn-primary" id="btnsubmit" type="button">Save</button>  
         <button class="btn btn-danger" data-dismiss="modal" id="btncancel" type="button">Cancel</button>  
       </div>  
Here js detect when users close or cancel modal
 //detect user close or cancel modal  
  $('#cancel,#btncancel').on("click", function(e) {  
     console.log('modal cancel or close');  
   });  

How to prevent user type in textarea not more than 150 charater

Hello Guys, if you have complex form that make users not typing to much character like in twtitter, i'm sure you have the reason about this but i don't care about your reason here is my demo for you
check this out

Please conside about this see my code bellow which is maxlength is prevent users type more than 150 character, so i choose this to make it simple
 <textarea class="form-control" maxlength="150" name="product_keterangan" required=""></textarea>  

Then i use this js just for count charachter
 var maxLength = 150;  
 $('textarea').keyup(function() {  
  var length = $(this).val().length;  
  var length = maxLength-length;  
  $('#chars').text(length);  
 });  

Tuesday 20 October 2015

Change Background Color in The First Div by Event Click Jquery

Hello Guys, quick Tutorial i have some task today that make users know where is products new by giving backgrond colour so i choose jquery by event click

I'm Not giving explanantion ya, just go here the demo


Saturday 17 October 2015

PREVENT MODAL BOOTSRAP CLOSE BY CLICK AREA MODAL

Hello guys, good night here. to night i will give short tutorial about prevent modal bootsrap close by click around div. Sometime as programmers we need to guide users to follow our instruction. i have some form that users should close modal by click close button or cross button in modal cause i have design when user cancel or close it some data will remove frommy table but depend on your design.

so here is my simple demo here

the source came from http://stackoverflow.com/questions/22207377/disable-click-outside-of-bootstrap-model-area-to-close-modal  

Monday 5 October 2015

Dekat dengan-Nya terasa semangat

Pagi ini aku seperti biasa bangun dan merasakan hal yang biasa tapi pagi ini ada hal yang kupaksakan, mencoba untuk berdoa dan kenal dia lagi dari tulisanNya di alkitab ini, ah sudah lama gak ngerasaain ketika nyanyi itu serasa ada yang ngercharger badan ini, jadi serasa onfire begitu ntah lah ini hanya  efek psikologi or not !

Tapi benar aja kadang-kadang aku sudah lupa bagaimana caranya mengucap syukur toh gak ada yang namanya belajar itu lupa atau malas itu normal toh selama masih jadi manusia.

pagi ini aku baca ayat di Yesaya lupa ayatnya karena sudah ku tutup dan tinggal ke warung beli kopi dan kue 2 irit di tanah rantau :p

yang intinya ketika kita sebagai anak-anak Tuhan (Cie anak Tuhan) jangan pura-pura ketika beribadah, dan memberi persembahan, dan yang lebih mainstreamnya adalah Tuhan jijik melihat kita membawa persembahan (hemat donk uang ku jadi gak keluar uang lagi buat persembahan) 

Mari tetap dekat denganNya, kalau gak tahu caranya biar dekat cari teman atau komunitas yang baik karena itu sangat membantu mu untuk mengingat bagaimana caranya berdoa dan memberi, kalau komunitas sudah dapat tinggal cari cewek biar lebih semangat tapi ingat jangan ceweknya jadi fokunya karena kalau gak dapat atau bahkan putus tengah jalan ntar jadi kecewa loh, by the way kalau ada temen cewek yang single rekomendasikan ke aku lah dulu,

Salam Lappet

Sunday 4 October 2015

Do Operatation Math Using Jquery

Hello long time no making tutorial about coding stuff cause i'm in bad mood condition i don't know it came every week, i have been developing projects inventory and i think this is the hard things for me as long as become programmers, so let check this out la

here is the demo

so let me declare one by one
$(document).on('change keyup blur','.all,.rusak',function(){
  calculateAmountDue();
});
//due amount calculation
function calculateAmountDue(){
var  all = $('.all').val();
var rusak = $('.rusak').val(); 
var tersedia = all-rusak;
$(".tersedia").val(tersedia);
 }

$(document).on('change keyup blur','.all,.rusak',function(){ calculateAmountDue(); });
This mean when input type has change or while typing text jquery do some command or execute some function, and the funtion do operation math, hope you understand what i mean ! Thanks for visiting me Salam Lappet