<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Quizzpot » English</title>
	
	<link>http://www.quizzpot.com</link>
	<description>Cursos en video gratuitos</description>
	<lastBuildDate>Fri, 03 May 2013 03:12:06 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/quizzpot-en" /><feedburner:info uri="quizzpot-en" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>LiveTreeGrid en ExtJS</title>
		<link>http://feedproxy.google.com/~r/quizzpot-en/~3/lCNT7w1bPoQ/</link>
		<comments>http://www.quizzpot.com/2010/12/livetreegrid-en-extjs/#comments</comments>
		<pubDate>Wed, 15 Dec 2010 19:47:38 +0000</pubDate>
		<dc:creator>Crysfel</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Español]]></category>
		<category><![CDATA[Portfolio]]></category>

		<guid isPermaLink="false">http://www.quizzpot.com/?p=2894</guid>
		<description><![CDATA[Componente desarrollado para la empresa Central de Reservas, permite desplegar en un TreeGrid una cantidad masiva de nodos.]]></description>
				<content:encoded><![CDATA[<p><strong>Project Name</strong> : LiveTreeGrid<br />
<strong>Client</strong> : Central de Reservas<br />
<span id="more-2894"></span></p>
<h3>Features</h3>
<ul>
<li>El TreeGrid puede desplegar 10,000 elementos sin problema alguno</li>
<li>Los nodos se van cargando dinámicamente de 200 por petición</li>
<li>Renderiza solamente los nodos que se visualizan</li>
</ul>
<h3>Video</h3>
<p>He creado un video donde explico un poco el funcionamiento del componente.<br />
<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0' width='560' height='345'><param name='movie' value='http://screenr.com/Content/assets/screenr_1116090935.swf' /><param name='flashvars' value='i=110080' /><param name='allowFullScreen' value='true' /><embed src='http://screenr.com/Content/assets/screenr_1116090935.swf' flashvars='i=110080' allowFullScreen='true' width='560' height='345' pluginspage='http://www.macromedia.com/go/getflashplayer'></embed></object></p>
<h3>Imágenes</h3>
<p>Algunas capturas para mostrar.</p>
<div class="gallery clearfix">
<a href="http://www.quizzpot.com/wp-content/uploads/2010/12/livetreegrid-demo-01.jpg"><img src="http://www.quizzpot.com/wp-content/uploads/2010/12/livetreegrid-demo-01-150x150.jpg" alt="" title="livetreegrid-demo-01" width="150" height="150" class="alignnone size-thumbnail wp-image-2899" /></a><a href="http://www.quizzpot.com/wp-content/uploads/2010/12/livetreegrid-demo-03.jpg"><img src="http://www.quizzpot.com/wp-content/uploads/2010/12/livetreegrid-demo-03-150x150.jpg" alt="" title="livetreegrid-demo-03" width="150" height="150" class="alignnone size-thumbnail wp-image-2898" /></a>
</div>
<img src="http://feeds.feedburner.com/~r/quizzpot-en/~4/lCNT7w1bPoQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.quizzpot.com/2010/12/livetreegrid-en-extjs/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://www.quizzpot.com/2010/12/livetreegrid-en-extjs/</feedburner:origLink></item>
		<item>
		<title>Show information from JSON format</title>
		<link>http://feedproxy.google.com/~r/quizzpot-en/~3/5xKywdyCXlo/</link>
		<comments>http://www.quizzpot.com/2010/10/show-information-from-json-format/#comments</comments>
		<pubDate>Wed, 13 Oct 2010 14:00:04 +0000</pubDate>
		<dc:creator>Crysfel</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Ext3]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.quizzpot.com/?p=2264</guid>
		<description><![CDATA[In this tutorial I want to show how to load the information contained in JSON format in a "Grid", is really easy and basic, but I think it is important to mention for those who are starting to work with this library.]]></description>
				<content:encoded><![CDATA[<p>This tutorial is very similar to the previous one where we saw how to <a href="http://www.quizzpot.com/2010/01/show-information-from-an-xml-file/">load data from an XML file</a>, the only thing we will change from the previous tutorial is the record that specifies the information it will contain and the &#8220;reader&#8221; because now we want to be able to read the JSON information returned by the server.</p>
<p><!-- image 1 --></p>
<div class="example"><img src="http://www.quizzpot.com/wp-content/uploads/2009/07/gridjson1.jpg" alt="Image of the grid" />
<p>Final Image</p>
</div>
<h3>Resources</h3>
<p>Let&#8217;s download the <a href="http://www.quizzpot.com/wp-content/uploads/2009/07/gridjson.zip">resources</a> for this tutorial, unzip them and copy the files inside of the folder &#8220;grid&#8221; on our Web server already installed.</p>
<h3>Packaging the tutorial</h3>
<p>As we have always done it in this course, we will package the code we will use for this tutorial, remember that this is fundamental and very important, believe me I will never get tired of saying this.</p>
<pre name="code" class="javascript">
Ext.ns('com.quizzpot.tutorial');

com.quizzpot.tutorial.GridJsonTutorial = {
	init: function(){		
		//code goes here
}

Ext.onReady(com.quizzpot.tutorial.GridJsonTutorial.init,com.quizzpot.tutorial.GridJsonTutorial);
</pre>
<h3>The JSON we&#8217;re going to use</h3>
<p>Now let&#8217;s define the information that the grid will display, for simplicity I will write the information directly into the code, but remember that this information can be in a database, a text file, Web service or it can come from elsewhere, but for now we will &#8220;hardcoded&#8221; it.</p>
<pre name="code" class="php">
&lt;?php
	header(&quot;Content-Type: text/plain&quot;); 
	
	$data = array(
		'success'=&gt;true,
		'total'=&gt;11,
		'data'=&gt;array(
			array('city'=&gt;'Mexico city','visits'=&gt;684,'pageVisits'=&gt;4.11,'averageTime'=&gt;'00:06:53'),
			array('city'=&gt;'La Victoria','visits'=&gt;443,'pageVisits'=&gt;4.39,'averageTime'=&gt;'00:07:28'),
			array('city'=&gt;'Madrid','visits'=&gt;380,'pageVisits'=&gt;3.11,'averageTime'=&gt;'00:05:22'),
			array('city'=&gt;'Providencia','visits'=&gt;204,'pageVisits'=&gt;3.83,'averageTime'=&gt;'00:08:20'),
			array('city'=&gt;'Bogota','visits'=&gt;204,'pageVisits'=&gt;3.26,'averageTime'=&gt;'00:04:57'),
			array('city'=&gt;'Puerto Madero','visits'=&gt;192,'pageVisits'=&gt;3.56,'averageTime'=&gt;'00:05:07'),
			array('city'=&gt;'Monterrey','visits'=&gt;174,'pageVisits'=&gt;3.90,'averageTime'=&gt;'00:06:06'),
			array('city'=&gt;'Barcelona','visits'=&gt;145,'pageVisits'=&gt;3.28,'averageTime'=&gt;'00:05:39'),
			array('city'=&gt;'Caracas','visits'=&gt;132,'pageVisits'=&gt;4.55,'averageTime'=&gt;'00:06:27'),
			array('city'=&gt;'Rosario','visits'=&gt;116,'pageVisits'=&gt;2.44,'averageTime'=&gt;'00:04:30'),
			array('city'=&gt;'Oaxaca','visits'=&gt;108,'pageVisits'=&gt;1.73,'averageTime'=&gt;'00:02:37')
		)
	);
	
	
	echo json_encode($data);
?&gt;
</pre>
<h3>Creating the “Record”</h3>
<p>Once we have defined the format in which the information is delivered to the client (via AJAX), we can create the &#8220;Record&#8221; we will display in the table.</p>
<pre name="code" class="javascript">
var Record = Ext.data.Record.create([
	{name: 'city'},
	{name: 'visits', type:'float'},
	{name: 'pageVisits', type:'float'},
	{name: 'averageTime'}
]);
</pre>
<p>The previous code should look familiar because we have reviewed in <a href="http://www.quizzpot.com/2009/06/reading-information-in-json-format/">previous tutorials</a>, basically we create a &#8220;record&#8221; with the fields we need to display and that are returned by the server, and define (in some cases) the type of information of the field.</p>
<h3>Creating the “Reader”</h3>
<p>Now let&#8217;s write the &#8220;Reader&#8221; so the store can interpret the information given to us in JSON format.</p>
<pre name="code" class="javascript">
var reader = new Ext.data.JsonReader({
   totalRecords: "total", 
   root: "data"               
}, Record);
</pre>
<p>For this case we used the component &#8220;JsonReader&#8221; and we configured the field of the total of records and the root field which is the principal information.</p>
<h3>Creating the Store and loading the information</h3>
<p>The next thing we need to do is create the store which shall contain the information locally in order to be manipulated by the grid.</p>
<pre name="code" class="javascript">
var store = new Ext.data.Store({
	url: 'gridjson.php',
	reader: reader
});

store.load();
</pre>
<p>You can see that we have configured the &#8220;url&#8221; that we are going to use to request the information with Ajax, also we have assigned the &#8220;Reader&#8221; we created earlier, finally we &#8220;load&#8221; the store.</p>
<h3>Saving a few lines of code</h3>
<p>So far all we&#8217;ve done is get the information from the server and save it on the store, all the previous lines of code can be reduced substantially as follows:</p>
<pre name="code" class="javascript">
var store = new Ext.data.JsonStore({
	url: 'gridjson.php',
	root: 'data',
	fields: ['city',{name:'visits',type:'float'},{name:'pageVisits',type:'float'},'averageTime']
});

store.load();
</pre>
<p>With the previous lines we do exactly the same as we did before, this is convenient when using JSON as a format for information transfer, so the decision to do it in one way or another is up to the developer.</p>
<h3>Creating the Grid</h3>
<p>Let&#8217;s create the grid to display the information contained in the store we created previously.</p>
<pre name="code" class="javascript">
var grid = new Ext.grid.GridPanel({
	store: store, // <--- we assign the store with the information we're going to use
	columns: [
		new Ext.grid.RowNumberer(),
		{header:'City', dataIndex:'city',sortable: true},
		{header:'Visits', dataIndex:'visits',sortable: true},
		{header:'Page/Visits', dataIndex:'pageVisits',sortable: true},
		{header:'Average Time', dataIndex:'averageTime', width:150,sortable: true}
	],
	border: false,
	stripeRows: true
});
</pre>
<p>We're not doing anything special, we only assigned the store to use, we defined the columns and assign a proper of the "Record" in the store to each column, we also created a column where the rows are numbered, we removed the border so when a table is entered the window will look good and at last we added alternating lines to the rows.</p>
<h3>Displaying the grid</h3>
<p>There are several ways to display the grid on the screen, this time we will use a window.</p>
<pre name="code" class="javascript">
var win = new Ext.Window({
	title: 'Grid example',
	layout: 'fit',
	width: 510,
	height:350,
	items: grid
});

win.show();
</pre>
<p>If you update the browser you will see something like the following image.</p>
<p><!-- imagen 1 --></p>
<div class="example"><img src="http://www.quizzpot.com/wp-content/uploads/2009/07/gridjson1.jpg" alt="Image of the grid" />
<p>Final Image</p>
</div>
<h3>Conclusions</h3>
<p>So far we have seen how to display information in different formats, which is really simple. In the next chapter we will see how to page this information, every time it gets more interesting so don't forget to subscribe to the Feeds or by email, also remember that use Twitter (quizzpot) to show updates and what we are doing in Quizzpot.</p>
<p>If you have any questions or suggestions please leave your comments and don't forget to become a fan in our Facebook page.</p>
<img src="http://feeds.feedburner.com/~r/quizzpot-en/~4/5xKywdyCXlo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.quizzpot.com/2010/10/show-information-from-json-format/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.quizzpot.com/2010/10/show-information-from-json-format/</feedburner:origLink></item>
		<item>
		<title>Show information from an XML file</title>
		<link>http://feedproxy.google.com/~r/quizzpot-en/~3/INDQvcKSBVg/</link>
		<comments>http://www.quizzpot.com/2010/10/show-information-from-an-xml-file/#comments</comments>
		<pubDate>Thu, 07 Oct 2010 19:23:58 +0000</pubDate>
		<dc:creator>Crysfel</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Ext3]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.quizzpot.com/?p=2230</guid>
		<description><![CDATA[Today I will show how to load information into a grid from an XML file, this is something very easy to do and useful when developing applications.]]></description>
				<content:encoded><![CDATA[<h3>Resources</h3>
<p>To continue we need to download the <a href="http://www.quizzpot.com/wp-content/uploads/2009/07/gridxml.zip">resources</a>, and copy the three files within our <a href="http://www.quizzpot.com/2009/03/basic-installation-of-the-framework/">Web server</a>, we have been working inside the folder &#8220;course&#8221; where we already have the Ext JS library and we already created a folder called &#8220;grids&#8221; for this chapter.</p>
<p>I have prepared a <a href="http://www.quizzpot.com/demos/extjs/grids/gridxml.html">demo</a> to show you what we&#8217;re going to do in this tutorial.</p>
<p><!-- imagen 1 --></p>
<div class="example"><img src="http://www.quizzpot.com/wp-content/uploads/2009/07/xmlgrid.jpg" alt="gridpanel" />
<p>Final example</p>
</div>
<h3>Packaging the code</h3>
<p>We know that packaging our code is really important and is a good practice, so let&#8217;s create the namespace for this tutorial.</p>
<pre name="code" class="javascript">
Ext.ns('com.quizzpot.tutorial');

com.quizzpot.tutorial.GridXmlTutorial = {
	init: function(){		
		//code goes here
	}
}

Ext.onReady(com.quizzpot.tutorial.GridXmlTutorial.init,com.quizzpot.tutorial.GridXmlTutorial);
</pre>
<h3>The XML we&#8217;re going to use</h3>
<p>We will use XML as our data source, such data may be contained in a database, Web service, file, etc..To make things simpler in this example I have put information directly in the source code as follows:</p>
<pre name="code" class="xml">
&lt;?php
	header(&quot;Content-Type: text/xml&quot;); 
	
	echo '&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;';
?&gt;

&lt;people&gt;
	&lt;person&gt;
		&lt;name&gt;Jack Slocum&lt;/name&gt;
		&lt;age&gt;32&lt;/age&gt;
		&lt;position&gt;Chief Software Architect and Founder&lt;/position&gt;
		&lt;company&gt;Ext JS&lt;/company&gt;
	&lt;/person&gt;
	&lt;person&gt;
		&lt;name&gt;Sasha Cohen&lt;/name&gt;
		&lt;age&gt;24&lt;/age&gt;
		&lt;position&gt;Figure Skating&lt;/position&gt;
		&lt;company&gt;&lt;/company&gt;
	&lt;/person&gt;
	&lt;person&gt;
		&lt;name&gt;John Resig&lt;/name&gt;
		&lt;age&gt;24&lt;/age&gt;
		&lt;position&gt;JavaScript Developer&lt;/position&gt;
		&lt;company&gt;Mozilla Corporation&lt;/company&gt;
	&lt;/person&gt;
	&lt;person&gt;
		&lt;name&gt;Sara Mcfly&lt;/name&gt;
		&lt;age&gt;35&lt;/age&gt;
		&lt;position&gt;Tester&lt;/position&gt;
		&lt;company&gt;Google&lt;/company&gt;
	&lt;/person&gt;
	&lt;person&gt;
		&lt;name&gt;Crysfel Villa&lt;/name&gt;
		&lt;age&gt;25&lt;/age&gt;
		&lt;position&gt;Software Developer&lt;/position&gt;
		&lt;company&gt;JWM Solutions&lt;/company&gt;
	&lt;/person&gt;
	&lt;person&gt;
		&lt;name&gt;Felicia Day&lt;/name&gt;
		&lt;age&gt;30&lt;/age&gt;
		&lt;position&gt;Actress&lt;/position&gt;
		&lt;company&gt;&lt;/company&gt;
	&lt;/person&gt;
	&lt;person&gt;
		&lt;name&gt;Collis Ta'eed&lt;/name&gt;
		&lt;age&gt;29&lt;/age&gt;
		&lt;position&gt;CEO&lt;/position&gt;
		&lt;company&gt;Envato&lt;/company&gt;
	&lt;/person&gt;
&lt;/people&gt;
</pre>
<h3>The record “Person”</h3>
<p>We&#8217;re going to display the information in XML on the grid, these are facts of people, therefore we need to create the record &#8220;Person&#8221; and map it to the node &#8220;person&#8221; of XML.</p>
<pre name="code" class="javascript">
var Person = Ext.data.Record.create([
	{name: 'name'},
	{name: 'position'},
	{name: 'age', type:'float'},
	{name: 'company'}
]);
</pre>
<h3>Creating the “Reader”</h3>
<p>Now let&#8217;s create the &#8220;reader&#8221; that will be assigned to the &#8220;store&#8221;:</p>
<pre name="code" class="javascript">
var reader = new Ext.data.XmlReader({
	record: "person"               
}, Person); 
</pre>
<p>In the previous code we have defined in the configuration of the XmlReader, the property &#8220;record&#8221; with the value &#8220;person&#8221;, by doing this the &#8220;reader&#8221; will be able to go to the node &#8220;person&#8221; (in XML) and retrieve the information contained in the object &#8220;Person&#8221;.</p>
<h3>Creating the Store and loading information</h3>
<p>The next step is to create the &#8220;Store&#8221; and load the XML information like this:</p>
<pre name="code" class="javascript">
var store = new Ext.data.Store({
	url: 'xml.php',
	reader: reader
});
		
store.load(); 
</pre>
<p>First we define the &#8220;url&#8221; where we&#8217;re going to search for the XML using Ajax, in the second configuration parameter we assigned the &#8220;reader&#8221; to the &#8220;Store&#8221;.</p>
<p>Once created the store we can use the method &#8220;load&#8221; to make the &#8220;Ajax&#8221; request and receive the information.</p>
<p>So far we have only defined the data source by making the necessary configurations. If you still have doubts about the &#8220;Store&#8221;, I recommend you to read <a href="http://www.quizzpot.com/2009/06/reading-information-in-xml/">the tutorial</a> where we talked specifically about this component.</p>
<h3>Creating the Grid</h3>
<p>Once we have the information ready to display it in the table, we can start creating the grid as follows:</p>
<pre name="code" class="javascript">
var grid = new Ext.grid.GridPanel({
	store: store, //assigning the data source
	columns: [ //creating the columns
		new Ext.grid.RowNumberer(), //numbering the rows
		{header:'Name', dataIndex:'name',sortable: true},
		{header:'Company', dataIndex:'company',sortable: true},
		{header:'Position', dataIndex:'position',width:230,sortable: true},
		{header:'Age', dataIndex:'age', width:40,sortable: true}
	],
	border: false, //removing the bordering
	stripeRows: true //assigning the stripes to the rows
});
</pre>
<p>With this simple configuration we created a very basic but attractive table, we have studied the code in the previous tutorial, but I will review the properties used in this grid:</p>
<p>“store”: This property defines the data source used in the grid.<br />
“columns”: we define the columns that the grid will have, this part is really important because we link the columns with the information that is going to be displayed (dataIndex).<br />
“border”: This property is inherited from the component Panel and by assigning the value &#8220;false&#8221; we remove the border, we do this because we put the grid in a window.<br />
“stripeRows”: By assigning the value &#8220;true&#8221; we stripe the rows this will make it easy to see the information, by default is &#8220;false&#8221;.</p>
<h3>Creating the window</h3>
<p>Finally, let&#8217;s put the grid inside of a window:</p>
<pre name="code" class="javascript">
var win = new Ext.Window({
	title: 'Grid example',
	layout: 'fit', // <--- 
	width: 510,
	height:350,
	items: grid
});

win.show();
</pre>
<p>The only important thing in this setting and we probably do not know (if we have taken this course from the beginning) is the setup "layout" to whom we are assigning the value "fit", this value will display the table occupying one hundred percent of the window, otherwise the grid will not be displayed completely, but I will talk about the layouts in the future tutorials.</p>
<p><!-- imagen 1 --></p>
<div class="example"><img src="http://www.quizzpot.com/wp-content/uploads/2009/07/xmlgrid.jpg" alt="gridpanel" />
<p>If all went well, you should see this screen</p>
</div>
<h3>Conclusions</h3>
<p>We have seen how easy it is to display information from a XML into a grid, we also appreciated the engineering implement on the Ext JS library, because the creation of the grid is the same for the different formats (XML, JSON, Array), the only thing we changed was the "Store" and the grid works the same, this is an advantage in terms of the maintenance of systems is concerned.</p>
<p>If you have any questions or suggestions feel free to leave a comment in this post, also don't forget to subscribe to <a href="http://feeds2.feedburner.com/quizzpot-en">our feeds</a> or follow us on <a href="http://twitter.com/quizzpot">Twitter (@quizzpot)</a> to be updated.</p>
<img src="http://feeds.feedburner.com/~r/quizzpot-en/~4/INDQvcKSBVg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.quizzpot.com/2010/10/show-information-from-an-xml-file/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.quizzpot.com/2010/10/show-information-from-an-xml-file/</feedburner:origLink></item>
		<item>
		<title>Win a copy of ExtJS in Action</title>
		<link>http://feedproxy.google.com/~r/quizzpot-en/~3/6n1ZeJvhp84/</link>
		<comments>http://www.quizzpot.com/2010/10/win-a-copy-of-extjs-in-action/#comments</comments>
		<pubDate>Tue, 05 Oct 2010 14:00:09 +0000</pubDate>
		<dc:creator>Crysfel</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Ext3]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Feebies]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.quizzpot.com/?p=2488</guid>
		<description><![CDATA[In this month of October we opened a new phase in Quizzpot and to celebrate we are going to make a giveaway that many people would like to participate.]]></description>
				<content:encoded><![CDATA[<h3>UPDATE: The winner!</h3>
<p>Congratulations to <strong>Dichi Al Faridi</strong>! He&#8217;s the winner!</p>
<p><object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0' width='560' height='345'><param name='movie' value='http://screenr.com/Content/assets/screenr_1116090935.swf' /><param name='flashvars' value='i=119943' /><param name='allowFullScreen' value='true' /><embed src='http://screenr.com/Content/assets/screenr_1116090935.swf' flashvars='i=119943' allowFullScreen='true' width='560' height='345' pluginspage='http://www.macromedia.com/go/getflashplayer'></embed></object></p>
<h3>More tutorials</h3>
<p>Today we will begin to publish tutorials more often, they will focus on the functionality and integration of advanced ExtJS components, in order to spread the correct use of the library.</p>
<p>I&#8217;d like to take this opportunity to invite all the readers to participate in writing tutorials, is an excellent way to participate in this site and share your knowledge with the community; some readers <a href="http://www.quizzpot.com/author/manduks/">have already participated</a> and we are very grateful, if you are interested please <a href="http://www.quizzpot.com/contact/">contact me</a>.</p>
<h3>Giveaway</h3>
<p>To celebrate this new phase of Quizzpot we are giving away the book &#8220;<a href="http://www.manning.com/garcia/">ExtJS in Action</a>&#8221; by <a href="http://twitter.com/tdgi"> Jesus Garcia</a> in the digital version (PDF), this book is excellent to get started with ExtJS also contains advanced topics to properly develop your applications.</p>
<p>To participate in this giveaway you only need to leave a comment on this post and make sure to write your <a href="http://twitter.com/quizzpot">Twitter</a> account or email address, so we can contact you. Comments are closed on October 18, 2010 at 24:00 GMT-5, the winner will receive an original registered copy with the download link directly from MEAP.</p>
<h3>Terms and Conditions</h3>
<p>You can participate only once, if the winner has left more than one comment he will be disqualified and an alternate winner selected.</p>
<p>If the Twitter account or email of the winner does not exist or is invalid, we will select another winner.</p>
<p>If the winner does not respond within the next 24 hours, we will draw another winner.</p>
<p>The comments made in our English and Spanish section will participate in the same giveaway, we will <b>not</ b> have 2 different giveaways.</p>
<p>The draw will be made using <a href="http://www.random.org/">www.random.org</a> and will be recorded using <a href="http://screenr.com/">screenr.com</a>.</p>
<p>The winner will be announced in this post, via <a href="http://twitter.com/quizzpot">Twitter</a> and <a href="http://www.facebook.com/pages/Quizzpot / 299875756793 ">Facebook </a>, so be sure to comeback to check if you are the winner.</p>
<img src="http://feeds.feedburner.com/~r/quizzpot-en/~4/6n1ZeJvhp84" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.quizzpot.com/2010/10/win-a-copy-of-extjs-in-action/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		<feedburner:origLink>http://www.quizzpot.com/2010/10/win-a-copy-of-extjs-in-action/</feedburner:origLink></item>
		<item>
		<title>Binding information from an array to a grid</title>
		<link>http://feedproxy.google.com/~r/quizzpot-en/~3/KBXyXKfrZ0c/</link>
		<comments>http://www.quizzpot.com/2010/09/binding-information-from-an-array-to-a-grid/#comments</comments>
		<pubDate>Sat, 25 Sep 2010 15:50:20 +0000</pubDate>
		<dc:creator>Crysfel</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Ext3]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.quizzpot.com/?p=2222</guid>
		<description><![CDATA[One of the most interesting components from ExtJS are the grids, which provide us the ability to display information in a simple and orderly way.]]></description>
				<content:encoded><![CDATA[<p>In this tutorial we will learn how to use the components of a basic GridPanel such as DataStore (or data repository), ColumnModel, and SelectionModel.</p>
<h3>Packaging the tutorial</h3>
<p>Let&#8217;s package the code first, to avoid conflicts with other variables.</p>
<pre name="code" class="javascript">
Ext.ns('com.quizzpot.tutorial');   
  
Ext.BLANK_IMAGE_URL = '../ext-3.0/resources/images/default/s.gif';   
  
com.quizzpot.tutorial.ArrayGridTutorial = {   
    init: function(){   
        //The code of the tutorial goes here
    }
}   

Ext.onReady(com.quizzpot.tutorial.ArrayGridTutorial.init,com.quizzpot.tutorial.ArrayGridTutorial);
</pre>
<h3>The Store</h3>
<p>The next thing we need to do is define the data repository, which is where we will retrieve the data, in this case we are going to work with static data stored in a two-dimensional array like this:</p>
<pre name="code" class="javascript">
//Two-dimensional array
var myData = [
	['3m Co',71.72,0.02,0.03,'9/1 12:00am'],
	['Alcoa Inc',29.01,0.42,1.47,'9/1 12:00am'],
	['Altria Group Inc',83.81,0.28,0.34,'9/1 12:00am'],
	['American Express Company',52.55,0.01,0.02,'9/1 12:00am'],
	['American International Group, Inc.',64.13,0.31,0.49,'9/1 12:00am'],
	['AT&#038;T Inc.',31.61,-0.48,-1.54,'9/1 12:00am'],
	['Boeing Co.',75.43,0.53,0.71,'9/1 12:00am'],
	['Caterpillar Inc.',67.27,0.92,1.39,'9/1 12:00am']
];
</pre>
<p>Now, let&#8217;s define an &#8220;Ext.data.ArrayStore&#8221; that will be responsible for reading the data array, in order to do this we need to set the reference name of the data column and the type of data it contains.</p>
<pre name="code" class="javascript">
//creating the data repository
var store = new Ext.data.ArrayStore({
	fields: [
	   {name: 'company'},
	   {name: 'price', type: 'float'},
	   {name: 'change', type: 'float'},
	   {name: 'pctChange', type: 'float'},
	   {name: 'updated', type: 'date', dateFormat: 'n/j h:ia'}
	]
});
store.loadData(myData);
</pre>
<p>The attribute &#8220;name&#8221; defines the name by which we will reference the first data column, the column called &#8220;price&#8221; is a reference to the second column and so on.</p>
<p>You can use the &#8220;type&#8221; attributes which defines the data type of the column, &#8220;dateFormat&#8221; defines the format of the columns that have a date format (see ExtJS API for more information).</p>
<h3>The Grid</h3>
<p>Now we are ready to create our grid by using the object &#8220;Ext.grid.GridPanel&#8221;:</p>
<pre name="code" class="javascript">
//Creating the object Ext.grid.GridPanel
var grid = new Ext.grid.GridPanel({
	title:'Company List',
	store: store,
	renderTo: document.body,
	columns: [
		{id:'company',header: "Company", width: 160, sortable: true, dataIndex: 'company'},
		{header: "Price", width: 75, sortable: true, dataIndex: 'price'},
		{header: "Change", width: 75, sortable: true, dataIndex: 'change'},
		{header: "% of change", width: 75, sortable: true, dataIndex: 'pctChange'},
		{header: "Updated", width: 85, sortable: true, renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'updated'}
	],
	stripeRows: true,
	height:250,
	width:500        
});
</pre>
<p>The grids, as well as the forms and other components inherit from &#8220;Ext.Panel&#8221;, this has already been seen in <a href="http://www.quizzpot.com/2009/07/what-is-a-panel-whats-the-functionality-how-do-you-create-one/">previous tutorials</a> so I guess you will be familiar with this.</p>
<p>The properties used are:<br />
&#8220;title&#8221;: property inherited from the Ext.Panel class, it defines the title of the panel.<br />
&#8220;store&#8221;: property that defines where the grid will get the data, (the Ext.data.ArrayStore defined previously).<br />
&#8220;renderTo&#8221;: defines where the grid is going to be rendered, receives a reference of the id of a DOM object or DIV.<br />
&#8220;columns&#8221;: defines the header of each column, in here the store date are associated through the property &#8220;name&#8221; defined in the store.<br />
&#8220;id&#8221;: defines the id of the column.<br />
&#8220;header&#8221;: defines the name displayed in the title of each column.<br />
&#8220;width&#8221;: sets the width of the column.<br />
&#8220;sortable&#8221;: boolean property that defines if we&#8217;re going to allow the ordering of the data by clicking the column heading.<br />
&#8220;dataIndex&#8221;: in here we define the value of the property &#8220;name&#8221; of the store, by doing this we associate the  data of the column of the store with the column of the table.<br />
&#8220;renderer&#8221;: with this property we can customize the data as shown in the column, I&#8217;ll explain that later.<br />
&#8220;stripeRows&#8221;: this property is used to show a slight shading spacing in the rows of the table.<br />
&#8220;height&#8221;: defines the height of the grid.<br />
&#8220;width&#8221;: define the width of the grid.</p>
<div class="example"><img src="http://www.quizzpot.com/wp-content/uploads/2009/06/tabla1.jpg" alt="Image of a grid" />
<p>Image of a basic grid</p>
</div>
<p>As we can see the grids have well-defined components, for the data management we need to use a store whose type depends on the type of information we need to handle; for example we have the &#8220;Ext.data.JSONStore&#8221; that handles information in JSON format, I suggest you to check the API to see more properties and types of data repositories.</p>
<h3>The ColumnModel</h3>
<p>Even though our grid is now ready and there are some things we might need that thankfully ExtJS has, one of those things are &#8220;Ext.grid.ColumnModel&#8221; which can be use to display the columns in the table and link them with the columns of the store, at the same time they provide functionalities such as selection of rows using a checkbox or a column for the enumeration of the rows.</p>
<p>Basically, creating a columnModel is similar to the content we&#8217;ve added in the property &#8220;columns&#8221; of our table.</p>
<pre name="code" class="javascript">
//Creating the object Ext.grid.ColumnModel
var myColumnModel = new Ext.grid.ColumnModel([
	{id:'company',header: "Company", width: 160, sortable: true, dataIndex: 'company'},
	{header: "Price", width: 75, sortable: true, dataIndex: 'price'},
	{header: "Change", width: 75, sortable: true, dataIndex: 'change'},
	{header: "% of change", width: 75, sortable: true, dataIndex: 'pctChange'},
	{header: "Updated", width: 85, sortable: true, renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'updated'}
]);
//our grid will  be changed to associated with the variable myColumnModel
var grid = new Ext.grid.GridPanel({
	title:'Company List',
	store: store,
	renderTo: document.body,
	cm: myColumnModel,//reference to columnModel
	stripeRows: true,
	height:250,
	width:500        
});
</pre>
<p>Now let&#8217;s number the rows and add a column of checkboxes for the selection.</p>
<pre name="code" class="javascript">
//Creating the object Ext.grid.ColumnModel
var myColumnModel = new Ext.grid.ColumnModel([
  	new Ext.grid.RowNumberer(),
  	new Ext.grid.CheckboxSelectionModel(),
  	{id:'company',header: "Company", width: 160, sortable: true, dataIndex: 'company'},
  	...
]);
</pre>
<div class="example"><img src="http://www.quizzpot.com/wp-content/uploads/2009/06/tabla2.jpg" alt="Image of a Grid" />
<p>A grid with numeration on the rows and checkboxes to select them</p>
</div>
<h3>The SelectionModel</h3>
<p>We are almost done, the only thing to add is a &#8220;Ext.grid.SelectionModel&#8221; which will indicate the mode of selection that our grid will have.</p>
<pre name="code" class="javascript">
//Creating a variable to link our object
var mySelectionModel = new Ext.grid.CheckboxSelectionModel({singleSelect: false});

//these are the settings we need for the grid
var grid = new Ext.grid.GridPanel({
	title:'Company List',
	store: store,
	renderTo: document.body,
	cm: myColumnModel, //reference of the columnModel
	sm: mySelectionModel, //reference of the selectionModel
	stripeRows: true,
	height:250,
	width:500        
});
</pre>
<div class="example"><img src="http://www.quizzpot.com/wp-content/uploads/2009/06/tabla3.jpg" alt="Image of a grid" />
<p>Characteristics of a grid in Ext JS</p>
</div>
<h3>Conclusions</h3>
<p>Today we have created a simple grid that reads data from an Array using an &#8220;ArrayStore&#8221;, then we created the table and we associated the store columns with the property &#8220;columns&#8221; of the table or creating a &#8220;ColumnModel&#8221; and finally we added a &#8220;SelectionModel&#8221; to manage the way to select rows, soon we will learn how to use different types of store, use events in the store and the table and &#8220;selecionModel.</p>
<p>If you have any question or suggestion feel free to leave a comment in this post. Don&#8217;t forget to follow us on <a href="http://twitter.com/quizzpot">Twitter (@quizzpot)</a> or add <a href="http://feeds2.feedburner.com/quizzpot-en">our feeds</a> to your favorite RSS reader.</p>
<img src="http://feeds.feedburner.com/~r/quizzpot-en/~4/KBXyXKfrZ0c" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.quizzpot.com/2010/09/binding-information-from-an-array-to-a-grid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.quizzpot.com/2010/09/binding-information-from-an-array-to-a-grid/</feedburner:origLink></item>
		<item>
		<title>Custom validations</title>
		<link>http://feedproxy.google.com/~r/quizzpot-en/~3/veLBLZc4F_U/</link>
		<comments>http://www.quizzpot.com/2010/09/custom-validations/#comments</comments>
		<pubDate>Fri, 17 Sep 2010 18:00:00 +0000</pubDate>
		<dc:creator>Crysfel</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Ext3]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.quizzpot.com/?p=2148</guid>
		<description><![CDATA[Many times it is necessary to create specific validations for our applications and are necessary to achieve the correct functionality, this tutorial explains how we can create "vtype's" to validate our ExtJS forms.]]></description>
				<content:encoded><![CDATA[<p>In the previous tutorial we saw how to do common validations, today we will learn how to do personalized validations and we&#8217;ll also see how to restrict the entry of characters in the text boxes.</p>
<p>I&#8217;ll invite you to test <a href="http://www.quizzpot.com/demos/extjs/forms/customvalidations.html">the demo</a> of what we&#8217;ll do in this tutorial.</p>
<p><!-- imagen 1 --></p>
<div class="example"><img src="http://www.quizzpot.com/wp-content/uploads/2009/08/vtype1.jpg" alt="Vtype in Ext JS" />
<p>Form with personalized validations</p>
</div>
<h3>Resources</h3>
<p>Before we start the tutorial don&#8217;t forget to download the <a href="href="http://www.quizzpot.com/wp-content/uploads/2009/08/vtypes.zip"">resources</a>, which only consist of two files: a HTML and JS; I  have created a form and I put it inside of a window, so what you need to do is add the validations to some fields.</p>
<h3>Display error messages</h3>
<p>If you execute the resources at this moment you will see that three fields are required, and when you click on the button &#8220;save&#8221; you will see some errors in red (if you don&#8217;t write anything in the text boxes), but only around the fields.</p>
<p><!-- imagen 2 --></p>
<div class="example"><img src="http://www.quizzpot.com/wp-content/uploads/2009/08/vtype2.jpg" alt="Vtype in Ext JS" />
<p>No error messages</p>
</div>
<p>The user should receive enough information to know what is wrong and how to fix it, so what we need to do is show an error message, to do this we only need to write the following lines at the beginning of the method &#8220;init&#8221;:</p>
<pre name="code" class="javascript">
Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'side';
</pre>
<p>The first line allows to display floating messages when we position the mouse over the text box, on the second line we display an error icon on the side of the field.</p>
<p><!-- image 3 --></p>
<div class="example"><img src="http://www.quizzpot.com/wp-content/uploads/2009/08/vtype3.jpg" alt="Vtype in Ext JS" />
<p>Displaying a floating message with the validation error</p>
</div>
<h3>Validate the age of majority</h3>
<p>In the &#8220;Date of birth&#8221; we&#8217;re going to calculate how many years we have from the given date of birth to today and validate that is over 18 years.</p>
<p>In the previous tutorial we saw how to use the &#8220;vtype&#8217;s&#8221; that are included in the ExtJS framework, today we&#8217;ll add more validations to the class &#8220;Ext.form.VTypes. The first thing we need to do is to extend the class like this:</p>
<pre name="code" class="javascript">
Ext.apply(Ext.form.VTypes,{

	//in here we're going to define the validations

});
</pre>
<p>The next things we need to do is define the &#8220;vtype&#8221; like this:</p>
<pre name="code" class="javascript">
Ext.apply(Ext.form.VTypes,{
	adult: function(val, field){
		try{
			var birth = field.getValue();
			var now = new Date();
			// The number of milliseconds in one year
			var ONE_YEAR = 1000 * 60 * 60 * 24 * 365;
		    	// Convert both dates to milliseconds
		    	var date1_ms = birth.getTime()
		    	var date2_ms = now.getTime()
		    	// Calculate the difference in milliseconds
		    	var difference_ms = Math.abs(date1_ms - date2_ms)
		    	// Convert back to years
		    	var years = difference_ms/ONE_YEAR;
			return years &gt;= 18;
		}catch(e){
			return false;
		}
	},
	adultText: 'You are underage!', //error message
	adultMask: / /  //regexp to filter the characters allowed
});
</pre>
<p>First we defined the name that the &#8220;VType&#8221; will receive, in this case &#8220;adult&#8221;, then we assign a function that receives two parameters: the contents of the field and the instance of the field that&#8217;s being validated, within this function we will have the code to validate and it must return &#8220;true&#8221; when the captured value is correct or &#8220;false&#8221; when the value is incorrect.</p>
<p>The next thing we need to do is define the text to display if the captured information is incorrect, we must remember that we have more validations within this object (Ext.form.VTypes), therefore to link the message with the function we only need to add the word &#8220;Text&#8221; at the end of the function name, in this case &#8220;adultText.</p>
<p>Optionally we can define a filter to capture only the correct characters, in order to do that we need to define a mask with the appropriate regular expression.</p>
<pre name="code" class="javascript">
adultMask: /[\d\/]/
</pre>
<p>The previous regular expression validates that the user can only enter digits and a slash, these characters are the only ones we need to enter a date in the format we have defined; please notice that the property is called &#8220;adultMask&#8221;, we only added at the end the word &#8220;Mask&#8221; to relate it with the validation we created previously.</p>
<p>Having defined the &#8220;vtype&#8221; we have to assign it to the field we need to validate, in this case the field &#8220;birth&#8221; of the form:</p>
<pre name="code" class="javascript">
{xtype:'datefield',fieldLabel:'Date of birth',name:'birth',allowBlank:false,format:'d/m/Y',vtype:'adult'},
</pre>
<p><!-- imagen 4 --></p>
<div class="example"><img src="http://www.quizzpot.com/wp-content/uploads/2009/08/vtype4.jpg" alt="Vtype in ExtJS" />
<p>Validating a date of birth (validating age of majority)</p>
</div>
<h3>Validate a phone number</h3>
<p>Now we will validate the format of a phone number, first we need to define the validation rules.</p>
<ul>
<li>Must contain 10 digits, for example: 8192847135</li>
<li>It can only accept parentheses, dashes, spaces and numbers,for example: (81) 92 847 135, 81 92-847-135, (81) 92-847-135, 81 92 84 71 35, 8192847135</li>
<li>It should only contain characters defined previously.</li>
</ul>
<p>With these rules we can now define the &#8220;vtype&#8221;:</p>
<pre name="code" class="javascript">
phone: function(value,field){
	return value.replace(/[ \-\(\)]/g,'').length == 10;
},
phoneText: 'Wrong phone number, please make sure it contains 10 digits',
phoneMask: /[ \d\-\(\)]/
</pre>
<p>The function defined in the property &#8220;phone&#8221; only removes the accepted characters (such as spaces, dashes, parentheses) leaving only the numbers, then validates that are ten digits; the mask accepts only the characters defined in the rules.</p>
<p>Finally we need to assign the &#8220;vtype&#8221; to the form field that we need to validate.</p>
<pre name="code" class="javascript">
{fieldLabel:'Phone number',name:'phone',vtype:'phone'},
</pre>
<p><!-- imagen 5 --></p>
<div class="example"><img src="http://www.quizzpot.com/wp-content/uploads/2009/08/vtype5.jpg" alt="Vtype in ExtJS" />
<p>Validating a phone number</p>
</div>
<h3>Validate a credit card</h3>
<p>In this last example we will validate the number of a credit card. First, we need to define the validation rules to have a clear idea of what we need to do.</p>
<ul>
<li>The number should have 16 digits, for example: 1234567891234567</li>
<li>We can only accept digits, spaces and dashes, for example:  1234 5678 9123 4567, 1234-5678-9123-4567</li>
<li>We should not accept any other character than the previous mentioned.</li>
</ul>
<p>You can see that these rules are very similar to the phone, so we can do a copy / paste and modify the code to fit these requirements.</p>
<pre name="code" class="javascript">
creditcard: function(value,field){
	return value.replace(/[ \-]/g,'').length == 16;
},
creditcardText: 'Wrong credit card number',
creditcardMask: /[ \d\-]/
</pre>
<p>I just made small changes because these rules are very similar, now we need to add the &#8220;vtype&#8221; to the field &#8220;credit&#8221;:</p>
<pre name="code" class="javascript">
{fieldLabel:'Credit card',name:'credit',vtype:'creditcard'},
</pre>
<p><!-- imagen 6 --></p>
<div class="example"><img src="http://www.quizzpot.com/wp-content/uploads/2009/08/vtype6.jpg" alt="Vtype in ExtJS" />
<p>Validating a credit card</p>
</div>
<h3>Conclusions</h3>
<p>Today we learned how to create our own client-side validations, as you can see it was really easy. ExtJS provides us an easy way to create custom validations and even put a mask on our fields.</p>
<p>If you have any question or suggestion feel free to leave a comment on this post. Don&#8217;t forget to follow us on <a href="http://twitter.com/quizzpot">Twitter (@quizzpot)</a> to be updated with the new tutorials we will post.</p>
<img src="http://feeds.feedburner.com/~r/quizzpot-en/~4/veLBLZc4F_U" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.quizzpot.com/2010/09/custom-validations/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.quizzpot.com/2010/09/custom-validations/</feedburner:origLink></item>
		<item>
		<title>Simple validations in the forms</title>
		<link>http://feedproxy.google.com/~r/quizzpot-en/~3/pjyrJgHiQxI/</link>
		<comments>http://www.quizzpot.com/2010/09/simple-validations-in-the-forms/#comments</comments>
		<pubDate>Wed, 08 Sep 2010 15:08:26 +0000</pubDate>
		<dc:creator>Crysfel</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Ext3]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.quizzpot.com/?p=2073</guid>
		<description><![CDATA[The validations are very important when we're saving the information the user entered, we should always validate the information we receive. In today's tutorial we will see how to use the validations ExtJS provides. ]]></description>
				<content:encoded><![CDATA[<p>It is very important to remember that we must validate the information the user enters in our application, both sides are equally important: the client side and server side. Using JavaScript, we can provide a better user experience when entering information in our application, but we must not forget that the server is responsible to validate everything it receives therefore we also have to do validate the information on the server and show the errors when they occurred.</p>
<p>This is a complicated task, but with Ext JS we can do this process faster by using the validations the Framework provides us. In this tutorial we will validate common information but later I will show you how to do complex validations.</p>
<h3>Resources</h3>
<p>Let&#8217;s download the <a href="http://www.quizzpot.com/wp-content/uploads/2009/08/simplevalidations-src.zip">resources</a> for this tutorial, I have created a <a href="http://www.quizzpot.com/2009/10/ext-js-basic-forms-and-fields/">form</a> with common fields such as &#8220;name, date, e-mail, Website, comment&#8221;, also there&#8217;s a PHP file which returns randomly some validation errors that we will show in the forms.</p>
<h3>Demo</h3>
<p>For everyone&#8217;s benefit I&#8217;ve created a <a href="http://www.quizzpot.com/demos/extjs/forms/simplevalidations.html">demo</a> of what we will see at the end of the tutorial, so go ahead a try it.</p>
<div class="example"><img src="http://www.quizzpot.com/wp-content/uploads/2009/08/validation1.jpg" alt="Validations in Ext JS" />
<p>Example of the tutorial finished</p>
</div>
<h3>Required fields</h3>
<p>If you run the application right now you will see that an <a href="http://www.quizzpot.com/2009/10/ext-js-basic-forms-and-fields/">empty form</a> is displayed, if we click on the &#8220;Save&#8221; button a request to the server is made through Ajax, then we get a message of &#8220;success&#8221; or &#8220;error&#8221;. It is very common to have required fields in an application, we should make sure that these fields are entered by the user and are being sent to the server (through Ajax).</p>
<p>To define a field as required we only need to use the property &#8220;allowBlank: false&#8221; in the fields we want to make mandatory, we will modify the form as follows.</p>
<pre name="code" class="javascript">
this.form = new Ext.form.FormPanel({
	url: 'simplevalidations.php',
	border:false,
	labelWidth: 80,
	defaults: {
		xtype:'textfield',
		width: 150
	},
	items:[
		{fieldLabel:'Name',name:'name',allowBlank:false}, //required field
		{xtype:'datefield',fieldLabel:'Start',name:'start',allowBlank:false}, //required field
		{xtype:'combo',fieldLabel:'Year',name:'year',triggerAction:'all',store:[2009,2008,2007,2006],readOnly:true},
		{fieldLabel:'Email',name:'email'},
		{fieldLabel:'Web site',name:'website'},
		{xtype:'textarea',fieldLabel:'Comment',name:'comment',allowBlank:false},//required field
		{xtype:'checkbox',fieldLabel:'',labelSeparator:'',boxLabel:'Available',name:'available'}
	]
});
</pre>
<p>In the previous code I&#8217;ve added the property &#8220;allowBlank: false&#8221; to the required fields, if you refresh the tutorial in your browser and click on the button &#8220;Save&#8221; you will get an error message and the required fields will be shown in red.</p>
<div class="example"><img src="http://www.quizzpot.com/wp-content/uploads/2009/08/validation2.jpg" alt="Validations in Ext JS" />
<p>Required field in the form</p>
</div>
<h3>Maximum of character in a TexField</h3>
<p>Normally we define in the database the number of characters we want in a field, so it is recommended to make sure the user can only enter something less to that number, otherwise we will have problems when saving the information. To do this we need only set the property &#8220;maxLength&#8221; with the maximum number we need.</p>
<pre name="code" class="javascript">
this.form = new Ext.form.FormPanel({
	//… code removed for simplicity
	items:[
		{fieldLabel:'Name',name:'name',allowBlank:false,maxLength:20},
		//… code removed for simplicity
	]
});
</pre>
<p>Now when we enter more than 20 characters in the field &#8220;name&#8221; an error appears telling us that something is wrong.</p>
<div class="example"><img src="http://www.quizzpot.com/wp-content/uploads/2009/08/validation3.jpg" alt="Validations in Ext JS" />
<p>Restrict number of characters in a field</p>
</div>
<h3>Common validations</h3>
<p>Ext JS has a component that contains some common validations and we can add the validations we need, in this tutorial we will use the default ones.</p>
<p>The component responsible of saving these validations is the &#8220;Ext.form.VTypes&#8221; and has four default validations:</p>
<h3>Only alpha characters</h3>
<p>The alpha characters are all letters and the underscore, it does not include numbers or other symbols. Let&#8217;s assign a &#8220;VType&#8221; to the field &#8220;name&#8221; to accept only these characters.</p>
<pre name="code" class="javascript">
this.form = new Ext.form.FormPanel({
	//… code removed for simplicity
	items:[
		{fieldLabel:'Name',name:'name',allowBlank:false,maxLength:20,vtype:'alpha'},
		//… code removed for simplicity
	]
});
</pre>
<p>With the property &#8220;VType&#8221; we can configure the validation we need, in this case we used &#8220;alpha&#8221; which is defined within the component &#8220;Ext.form.VTypes&#8221;, so don&#8217;t forget that.</p>
<div class="example"><img src="http://www.quizzpot.com/wp-content/uploads/2009/08/validation4.jpg" alt="Validations in Ext JS" />
<p>Only alpha characters</p>
</div>
<h3>Validate an e-mail</h3>
<p>A common validation is the e-mail, let&#8217;s assign the &#8220;VType&#8221; that corresponds to the field of email in our form as follows:</p>
<pre name="code" class="javascript">
this.form = new Ext.form.FormPanel({
	//… code removed for simplicity
	items:[
		//… code removed for simplicity

		{fieldLabel:'Email',name:'email',vtype:'email'}, // validating an e-mail

//… code removed for simplicity
	]
});
</pre>
<p>Thanks to Ext JS we don&#8217;t have to spend more than a minute to add that validation, now the form will look similar to the following screen when you enter a invalid e-mail.</p>
<div class="example"><img src="http://www.quizzpot.com/wp-content/uploads/2009/08/validation5.jpg" alt="Validations in Ext JS" />
<p>Validation of an e-mail</p>
</div>
<h3>Validate an URL</h3>
<p>Let&#8217;s see how to validate a Website address or &#8220;URL&#8221;.</p>
<pre name="code" class="javascript">
this.form = new Ext.form.FormPanel({
	//… code removed for simplicity
	items:[
		//… code removed for simplicity

		{fieldLabel:'Web site',name:'website',vtype:'url'}, //validating an URL

//… code removed for simplicity
	]
});
</pre>
<p>I&#8217;d like to emphasize that it also validates protocols such as &#8220;https&#8221; and &#8220;ftp&#8221;.</p>
<div class="example"><img src="http://www.quizzpot.com/wp-content/uploads/2009/08/validation6.jpg" alt="Validations in Ext JS" />
<p>Validation of an URL</p>
</div>
<h3>Validation in the server</h3>
<p>So far we have seen how to validate on the client side, but it is also important to validate on the server side, let&#8217;s see how we can display the validation errors that are caused on the server.</p>
<p>Ext JS has a feature that will save us a lot of time when we need to display the errors caused in the server, this feature will emphasize the exact area where and why the error was caused. To use this feature the server response should have the following format:</p>
<pre name="code" class="javascript">
{
	success: false,
	msg: 'General message of the error',
	errors: {
		field: 'Message of the reason of the error',
		anotherFieldError: 'what caused the error?'
       }
}
</pre>
<p>After defining the error messages, we need to edit the file &#8220;simplevalidations.php&#8221; and generate some test failures.</p>
<pre name="code" class="php">
$info = array(
	'success' =&gt; false,
	'msg' =&gt; 'There was an error saving the record',
	'errors' =&gt; array(
		'name' =&gt; $name.' is not an employee of this corporation',
		'email' =&gt; 'E-mail does not exist in the database',
		'comment' =&gt; 'The comment is to short'
	)
);
</pre>
<p>These fields are enough to accomplish the functionality we want, so just go ahead a refresh your browser and you will see something similar to the following image:</p>
<div class="example"><img src="http://www.quizzpot.com/wp-content/uploads/2009/08/validation7.jpg" alt="Validations in Ext JS" />
<p>Displaying validations errors caused in the server side</p>
</div>
<p>With this we can see that although the client validations are correct, the information may be incorrect due to our business logic, in this example the name of the person should exist in our catalog of employees (hypothetical example).</p>
<h3>Conclusions</h3>
<p>The validations are very important, today we saw how to use the default validations and we learned how to display error messages that are generated on the server. As you can see it was very easy validating fields with Ext JS.</p>
<p>If you have any questions or suggestions feel free to leave a comment on this post and don&#8217;t forget to follow us on <a href="http://twitter.com/quizzpot">Twitter</a> (@quizzpot) to be updated.</p>
<img src="http://feeds.feedburner.com/~r/quizzpot-en/~4/pjyrJgHiQxI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.quizzpot.com/2010/09/simple-validations-in-the-forms/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://www.quizzpot.com/2010/09/simple-validations-in-the-forms/</feedburner:origLink></item>
		<item>
		<title>Linked ComboBoxes with ExtJS</title>
		<link>http://feedproxy.google.com/~r/quizzpot-en/~3/KxLoSbKQrfQ/</link>
		<comments>http://www.quizzpot.com/2010/09/linked-comboboxes-with-extjs/#comments</comments>
		<pubDate>Thu, 02 Sep 2010 17:59:12 +0000</pubDate>
		<dc:creator>Crysfel</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Ext3]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.quizzpot.com/?p=2118</guid>
		<description><![CDATA[Sometimes the information we use in our applications is grouped into categories, in these situations the linked combos will help us to maintain these connections in a simple way.]]></description>
				<content:encoded><![CDATA[<p>In today&#8217;s tutorial we will create two combos that are related to each other, we&#8217;ll use the typical example countries and their respective states, the information of the state&#8217;s combo will be loaded with Ajax depending on the country selected in the first combo. I recommend you <a href="http://www.quizzpot.com/demos/extjs/forms/linked-cmb.html">test the demo</a> to be able to see the final result.</p>
<p><!-- imagen 1 --></p>
<div class="example"><img src="http://www.quizzpot.com/wp-content/uploads/2009/11/linked-cmb1.jpg" alt="Linked ComboBoxes with ExtJS" />
<p>Tutorial&#8217;s demo</p>
</div>
<h3>Resources</h3>
<p>Before I start explaning this tutorial you need to download the <a href="http://www.quizzpot.com/wp-content/uploads/2009/11/linked-cmb.zip">resources</a> and copy the content into a Web server because we will be using Ajax to load information.</p>
<h3>The information source</h3>
<p>Let&#8217;s write the code needed to generate the information the combos will display, for this example the information is in PHP arrays, but remember that you can retrieve it from a database, Web Service, a text file or elsewhere.</p>
<pre name="code" class="php"> 
$countries = array('Argentina','España','México','Perú','United States'); //step 1

$states = array( 			//step 2
	array('Buenos Aires','Córdoba','La Pampa','Mendoza','Santa Fe'),
	array('Asturias','Valencia','Barcelona','Toledo'),
	array('Distrito Federal','Nuevo León','Jalisco'),
	array('Arequipa','Puno','Tacna','Lima'),
	array('Texas','California','New york','Virginia')
);
</pre>
<p>In step one I have been defined the countries we will use in the first combo, these are five countries but the array can be bigger or smaller.</p>
<p>In step two I have defined the states of each country, it is important to mention that the connection is being made by the position in the arrays, let&#8217;s write the following code to linked both combos:</p>
<pre name="code" class="php">
$id = isset($_POST['id'])?$_POST['id']:-1;	//step 1
	
if($id > -1){					//step 2
	//show states
	echo toJSON($states[$id]);		//step 3
}else{
	//show contries
	echo toJSON($countries);		//step 4
}
</pre>
<p>In step one we retrieve the parameter &#8220;id&#8221; and verify the existence, if it hasn&#8217;t been sent we assign the value &#8220;-1&#8243; to the variable.</p>
<p>In step two we verify that the &#8220;id&#8221; is greater than &#8220;-1&#8243;, this tells us that our application is requesting the states of a country, the variable &#8220;id&#8221; must have the position of the requested country so in this part we decide what is going to be displayed: countries or states.</p>
<p>Step three is executed if the variable &#8220;id&#8221; contains the index of the selected country, so we can display the states of the requested index.</p>
<p>Step four is only implemented if the &#8220;id&#8221; is less than or equal to -1, this tells us that the application has requested the countries.</p>
<p>You probably noticed that we&#8217;re invoking the function &#8220;toJSON&#8221;, so let&#8217;s go ahead an write the function like this:</p>
<pre name="code" class="php">
function toJSON($array){
	$data=array(); $i=0;			//step 1
	$total = count($array);
	foreach($array as $key=>$value){	//step 2
		array_push($data,array(
			'value'=>$i++,		//step 3
			'label'=>$value
		));
	}
	
	return json_encode(array(		//step 4
		'total'=>$total,
		'data'=>$data
	));
}
</pre>
<p>The purpose of this function is to create the JSON we&#8217;re going to send to the combos.</p>
<p>In step one we created two variables: &#8220;data&#8221; and &#8220;i&#8221;, in the variable &#8220;data&#8221; we will store each country or state we will display in the combos, the variable &#8220;i&#8221; is very important because we will use it to create the connection between the combos, I will explain this in step three.</p>
<p>In step two, we create a loop that runs through the array we received as a parameter, this array contains the information we&#8217;re going to display in the combos.</p>
<p>In step three we are storing each element of the array in the variable &#8220;data&#8221;, you can see that we are creating an array with two properties &#8220;value&#8221; and &#8220;label&#8221;, these properties will be used by the combo, in the property &#8220;value&#8221; we assigned the value of &#8220;i&#8221;, this is the value sent as a parameter to request the states of the country selected in the first combo, the property &#8220;label&#8221; is only the text that will display each option in the combo.</p>
<p>In step four we return the information we collected previously in JSON format.</p>
<h3>Creating JsonStores</h3>
<p>Once we have defined the information we need to display we can create the combos, we already know that the combos use <a href="http://www.quizzpot.com/2009/10/combo-box-loaded-dynamically-and-remotely/">a Store</a> to manipulate the information displayed. There is a JS file (linked-cmb.js) in the resources you downloaded at the beginning of this tutorial, so let&#8217;s go ahead and edit it and within the function &#8220;getStore&#8221; you would write the following:</p>
<pre name="code" class="javascript">
getStore: function(){
	var store = new Ext.data.JsonStore({
		url:'linked-cmb.php',
		root:'data',
		fields: ['value','label']
	});
	return store;
}
</pre>
<p>In here we only created a JsonStore, with the fields we defined on the server, the previous code should be easy to understand because we have used it on several occasions, but I&#8217;d like to mention that I have decided to create a function to generate a Store because I need two with the same properties, and I didn&#8217;t want to rewrite the same code twice, so I just created a function that generates the stores as many time as necessary.</p>
<h3>Creating the Linked ComBoxes</h3>
<p>In the previous step we created a function that generates <a href="http://www.quizzpot.com/2009/06/reading-information-in-json-format/">one JsonStore</a>, so let&#8217;s create two of these so we can use them with each of the combos:</p>
<pre name="code" class="javascript">
this.countryStore = this.getStore();
this.stateStore = this.getStore();
</pre>
<p>The combo that will display the countries will have the following properties:</p>
<pre name="code" class="javascript">
this.countryCmb = new Ext.form.ComboBox({
	store: this.countryStore,
	id: 'country',
	valueField: 'value',
	displayField: 'label',
	triggerAction: 'all',
	emptyText: 'Select a Country',
	fieldLabel: 'Country'
});
</pre>
<p>There&#8217;s nothing complicated in the previous code, is just a typical configuration of a <a href="http://www.quizzpot.com/2009/10/combo-box-loaded-dynamically-and-remotely/">ComboBox</a>, the next thing we need to do is create a combo that will display the states of the selected country.</p>
<pre name="code" class="javascript">
this.stateCmb = new Ext.form.ComboBox({
	store: this.stateStore,
	disabled: true,		//Step 1
	id: 'state',
	valueField: 'value',
	displayField: 'label',
	triggerAction: 'all',
	mode: 'local',		//Step 2
	emptyText: 'Select a Contry first',
	fieldLabel: 'State'
});
</pre>
<p>This configuration has some differences from the previous one, these differences are very important and I will explain you why:</p>
<p>In step one we are disabling the combo, in order to force the user to select the country first, this step is optional but improves the usability by ensuring that the user does not make mistakes.</p>
<p>Step two is very important, if we don&#8217;t assign this configuration we will have a strange behavior because by assigning the property &#8220;mode: &#8216;local&#8217;&#8221; we ensure that there is no Ajax requests to the server when the user clicks on the combo to see the options.</p>
<h3>Displaying the combos in a window</h3>
<p>So far we have written code but still can not see anything on the screen, so now it&#8217;s time to render the components, for this example I will use a window with the following properties:</p>
<pre name="code" class="javascript">
this.window = new Ext.Window({
	title: 'Linked ComboBox',
	layout:'form',
	width:300,
	height:200,
	bodyStyle: 'padding:5px;background-color:#fff',
	items: [this.countryCmb,this.stateCmb]
});
this.window.show();
</pre>
<p><!-- imagen 2 --></p>
<div class="example"><img src="http://www.quizzpot.com/wp-content/uploads/2009/11/linked-cmb2.jpg" alt="Linked ComboBoxes with ExtJS" />
<p>Creation of the ComboBoxes</p>
</div>
<p> </p>
<h3>Adding the “listener”</h3>
<p>At this point we can see the combos, the combo of countries displays the information correctly but the combo of states is disabled and we can not do anything with it.</p>
<p>To interact with the components we need to add a <a href="http://www.quizzpot.com/2009/05/handling-events-on-dom-elements-and-components/">&#8220;listener&#8221;</a> to the first combo, in order to enable the combo of states when the first combo is selected and load the appropriate information.</p>
<pre name="code" class="javascript">
this.countryCmb.on('select',function(cmb,record,index){	//step 1
	this.stateCmb.enable();			//step 2
	this.stateCmb.clearValue();		//step 3
	this.stateStore.load({			//step 4
		params:{
			id:record.get('value')	//step 5
		}	
	});
},this);
</pre>
<p>In step one we added a &#8220;listener&#8221; to the event &#8220;select&#8221;, this event is triggered when the user selects an option from the combo, the function receives three parameters: the combo, the record and the index that has been selected.</p>
<p>In step two we only enable the combo of states.</p>
<p>In step three we remove the value of the combo of states, if the user has previously selected a country and state and we load new sates, the old value will be removed.</p>
<p>En el paso tres limpiamos el valor del combo de estados, esto permitirá que si el usuario ha seleccionado anteriormente un estado, cuando se carguen nuevos estados se limpiará el valor anterior.</p>
<p>In step four we are reloading the information of the Store of states with Ajax.</p>
<p>In step five we pass the parameter &#8220;id&#8221; which is going to be used by the server to decided which states must be returned.</p>
<p><!-- imagen 3 --></p>
<div class="example"><img src="http://www.quizzpot.com/wp-content/uploads/2009/11/linked-cmb1.jpg" alt="Linked ComboBoxes with ExtJS" />
<p>Linked combos</p>
</div>
<h3>Conclusions</h3>
<p>Following the steps in this tutorial we can create linked combos on the levels we need, we just need to assign a &#8220;listener&#8221; to the event &#8220;select&#8221; of the combo and within this &#8220;listener&#8221; reload the store of the combo.</p>
<p>Don&#8217;t forget to follow us on <a href="http://twitter.com/quizzpot">Twitter (@quizzpot)</a> to be updated of the new tutorials we will be publishing and also if you have any questions or suggestions feel free to leave a comment on this post.</p>
<img src="http://feeds.feedburner.com/~r/quizzpot-en/~4/KxLoSbKQrfQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.quizzpot.com/2010/09/linked-comboboxes-with-extjs/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		<feedburner:origLink>http://www.quizzpot.com/2010/09/linked-comboboxes-with-extjs/</feedburner:origLink></item>
		<item>
		<title>Graficador en ExtJS</title>
		<link>http://feedproxy.google.com/~r/quizzpot-en/~3/bTnQPRn963I/</link>
		<comments>http://www.quizzpot.com/2010/05/graficador-en-extjs/#comments</comments>
		<pubDate>Wed, 12 May 2010 21:00:03 +0000</pubDate>
		<dc:creator>Crysfel</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Español]]></category>
		<category><![CDATA[Ext3]]></category>
		<category><![CDATA[Portfolio]]></category>

		<guid isPermaLink="false">http://www.quizzpot.com/?p=2359</guid>
		<description><![CDATA[Componente desarrollado para la empresa TheHumanTalent, permite generar gráficas a partir de las parámetros definidos por el usuario.]]></description>
				<content:encoded><![CDATA[<p><strong>Project Name</strong> : Graficador en ExtJS<br />
<strong>Client</strong> : The Human Talent<br />
<span id="more-2359"></span></p>
<h3>Features</h3>
<ul>
<li>El usuario genera sus propias gráficas</li>
<li>El estado de las gráficas son guardadas en la base de datos</li>
<li>Las gráficas se pueden exportar a JPG</li>
<li>La gráfica se puede imprimir</li>
<li>Una gráfica se puede colapsar, expandir y mover en el área de trabajo</li>
</ul>
<h3>Imágenes</h3>
<div class="gallery clearfix">
<a href="http://www.quizzpot.com/wp-content/uploads/2010/05/ht-demo01.jpg"><img src="http://www.quizzpot.com/wp-content/uploads/2010/05/ht-demo01-150x150.jpg" alt="" title="ht-demo02" width="150" height="150" class="alignnone size-thumbnail wp-image-2360" /></a><a href="http://www.quizzpot.com/wp-content/uploads/2010/05/ht-demo02.jpg"><img src="http://www.quizzpot.com/wp-content/uploads/2010/05/ht-demo02-150x150.jpg" alt="" title="ht-demo02" width="150" height="150" class="alignnone size-thumbnail wp-image-2360" /></a><a href="http://www.quizzpot.com/wp-content/uploads/2010/05/ht-demo03.jpg"><img src="http://www.quizzpot.com/wp-content/uploads/2010/05/ht-demo03-150x150.jpg" alt="" title="ht-demo03" width="150" height="150" class="alignnone size-thumbnail wp-image-2360" /></a>
</div>
<img src="http://feeds.feedburner.com/~r/quizzpot-en/~4/bTnQPRn963I" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.quizzpot.com/2010/05/graficador-en-extjs/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		<feedburner:origLink>http://www.quizzpot.com/2010/05/graficador-en-extjs/</feedburner:origLink></item>
		<item>
		<title>Merry christmas</title>
		<link>http://feedproxy.google.com/~r/quizzpot-en/~3/Jb0WGSXikV4/</link>
		<comments>http://www.quizzpot.com/2009/12/merry-christmas/#comments</comments>
		<pubDate>Thu, 24 Dec 2009 17:22:57 +0000</pubDate>
		<dc:creator>Crysfel</dc:creator>
				<category><![CDATA[English]]></category>

		<guid isPermaLink="false">http://www.quizzpot.com/?p=2214</guid>
		<description><![CDATA[Merry Christmas and a happy New Year!]]></description>
				<content:encoded><![CDATA[<p><img src="http://www.quizzpot.com/wp-content/uploads/2009/12/merry-christmas-2009.jpg" alt="Merry Christmas" /></p>
<p>May you all enjoy these holidays with your family and friends, and have a very Happy Christmas and a new year of successes and challenges.</p>
<img src="http://feeds.feedburner.com/~r/quizzpot-en/~4/Jb0WGSXikV4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.quizzpot.com/2009/12/merry-christmas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.quizzpot.com/2009/12/merry-christmas/</feedburner:origLink></item>
	</channel>
</rss>
