Rhyne Design - Tutorials we create, stuff we find, ideas we want to share

Throw all your form fields into a Object with a few lines of jQuery code.

NOTE : I don't care if you don't like my Hungarian notation. 

Why?

Many times I see jQuery developers caching their form fields like this....

$field1 = $("#field1");

$field2 = $("#field2");

First of all, they should be passing  a form context first to increase performance by limiting the DOM lookup scope.. 

$form = $("#form_id");

$field1 = $("#field1",$form);

$field2 = $("#field2",$form);

Second, if you have a very long form the above code example can get very lengthy AND you have hard coded your id names to the jQuery selections. 

I do it this way... 

var $inputs = $("input, select");

var inputsObj = {};

$.each($inputs,function(){

$this = $(this);

var id = $this.attr("id");

inputsObj[id] = $(this);

});

Now if you want do something with your fields you can do this! 

inputsObj.field1.hide();

inputsObj.field2.val("//a value");

I think this a way more flexible approach to working with form fields..

Comments [0]

Early look at PDiPhone app I'm building.

Stephen Rhyne 206.412.5334

Comments [1]

9 Useful jQuery Calendar And Date Picker Plugins For Web Designers

I'm going to be adding some "snapshot" functionality to our web app "WebPDI". I found these resources useful. 

Comments [0]

Facebook Hopes to Revolutionize PHP with “Hip Hop”

Comments [0]

APItite || Really Easy Zoho CRM API Development

Comments [0]

Phonegap Seminar @codebits.eu from Brian LeRoux

Anyone interested in mobile application development should watch this video! I am getting more and more involved with this project. We are using Phonegap for an upcoming native iphone app

Filed under  //   iphone   mobile   phonegap  

Comments [0]

Easy Zoho Creator Form CSS with ZCStyles (Free on ZC Marketplace)

Just whipped up a little ZC function that makes it super easy to customize the look of  ALL your forms in all your applications. I got tired of having to make markup changes in many, many html views and links when using the form customization parameters.

Get it here on the marketplace

Filed under  //   CSS   Deluge Script   Map Function   Marketplace   ZC   Zoho   Zoho Creator  

Comments [0]

Tutorial : Consuming RESTful Resources (XML & JSON) in Zoho Creator

This post is in response to this Zoho Creator Forum Post

Using Zoho Creator's XML parsing capabilites.. Sounds daunting but it really isn't. Here's a small example of how you get your file, then turn it into an XMLLIST which then acts almost exactly like a regular list in Zoho Creator.


Let's walk through one..

Now this will be a getURL() example...

1. Create your REST URL call. This is the URL the getURL() goes OUT TO to retrieve the XML... Here's an example...

url = "http://mywebservice.com/api/dataform?param1=&param2=&param3=";

2. Now, we create a map variable to hold our response from the getURL() function. The false value tells the getURL to return a detailed response. THIS WE WANT for parsing XML.

    mapVariable = getUrl(url,false);

3. Now that we have our response in the mapvar, we need to grab the "string" response that came back when we called the getUrl() function. We do this by "getting" the "responseText" key. This is exactly the same way you grab a key out of other maps.

    stringResponse = mapvar.get("responseText");

4. Ok, now we have the whole XML response saved in the "stringResponse" variable. But at this point the XML isn't really actually XML it's actually a long "string" value. (Note: if you run an "info" log message on your stringResponse variable right now. YOU WON'T see the XML elements and you might think you did something wrong. YOU DIDN'T ZC doesn't show the XML markup in log messages unless you convert to XML then back to string. Ok, that was a TMI, but I just thought I would let you know.)

5. Ok let's convert that "string" value of stringResponse to XML!

xmlResponse = stringResponse.toXML();

6. Now, here's the hardest concept to understand I think for new users. Now that we have the REAL XML we need to message it a little bit so that we can get it in a format that's more usable in Zoho Creator.  

What we need to do is "target"/put our focus on the XML nodes that we want to use in our data. Basically, we want to POINT to the nodes of the records we want to create a list out of..Let's take a look at some examples....

<result>

     <data>

         <row></row>

         <row></row>

        <row></row>

   </data>

</result>

So in the above example the <rows> are what we want to import into Zoho Creator. So let's point our XPATH to that node "address".

result/data/row

Ok, let's do another example.. What if you just wanted to get the data OF THE FIRST <row>. Let's say our xml looked like this....

<result>

    <data>

         <row>

             <first_name>Rick</first_name>

             <last_name>James</last_name>

             <email>rjames@imrickjames.com</email>

         </row>

         <row></row>

        <row></row>

   </data>

</result>

In the above example we would just want to make our xpath.....

result/data/row[1]

this would xpath would return only the nodes inside <row> one.

7. Ok, once you have targeted the data nodes that you want to create a list out of, let's shorten our XML to reflect the desired path..

startPath = xmlResponse.executeXPath("result/data/row[1]");

For the rest of this example. Let's just go with all the <row>'s and use this XML... . so again our xpath for our startPath URL would be result/data/row

<result>

    <data>

         <row>

             <first_name>Rick</first_name>

             <last_name>James</last_name>

             <email>rjames@imrickjames.com</email>

         </row>

         <row>

            <first_name>Charlie</first_name>

             <last_name>Murphy</last_name>

             <email>cmurphy@charliemurphy.com</email>

         </row>

        <row>

            <first_name>Stephen</first_name>

             <last_name>Baldwin</last_name>

             <email>sbaldwin@realitytv.com</email>

        </row>

   </data>

</result>

 

8. Ok, now let's convert the XML to an XMLlist! Converting your data to a Zoho Creator XMLList() let's you ITERATE/LOOP through your desired XML nodes USING the built in "for each element" functionality already used for other lists.

xmllist = startPath.toXmlList();

9. Now we have our list!  We can do all sorts of great wonderous things once you have your XML data in this format.

Let's create "for each element" loop

    for each r in xmllist
    {
    }

10. Inside our loop we have to EXECUTE the xpath for each row's child nodes so that we can get the data out of it.

Here's how... 

    for each r in xmllist
    {

          firstName = r.executeXPath(''/row/first_name/text()');

           lastName = r.executeXPath(''/row/last_name/text()');

           email = r.executeXPath(''/row/email/text()');

    }

11. Notice that my Xpath's in my executeXpath() functions START WITH the node we LEFT OFF of in step 7 when we targeted our XML node!

12. Ok, so you have your data in the XML list and you know how to get the data into variables.. What else can you do?

Example 1. check to see if these email addresses are already in your Zoho Creator app form and IF THEY AREN'T in the desired form then INSERT that xml row into the desired Zoho form!

get all the email addresses....

getForm = form1[email != ""];

emailList = getForm.email.getAll();

 

    for each r in xmllist
    {

          firstName = r.executeXPath(''/row/first_name/text()');

           lastName = r.executeXPath(''/row/last_name/text()');

           email = r.executeXPath(''/row/email/text()');

           if(!emailList.contains(email))

           {

              insert into form1

              [

                  Added_User = zoho.loginuser

                 first_n ame = first_name

                 last_name = last_name

                  email = email

               ]

           }

    }

I hope this helps all of you that want to use this functionality but have struggled to wrap your head around it. I know it took me a little while to get used to.

Also, there are many other great things you can do with the Xpath functionalty. LIKE....

1. create a for each loop inside a loop

2. create node agnostic xpaths

3. MY FAVORITE stop using Xpath completely on XMLlists by converting your xml_list to a "list map"/associative array. See this post. 

Here is a great simple Xpath resource

Comments [2]

Zoho Creator Dev Community

This is in reply to : Snake eating it's own tail?

First,

Let us give credit to the developers who set the precedent of sharing knowledge and assisting others early on..(years back). I think it's safe to say that if they hadn't set this precedent we might not have this great ebb and flow of responses like we do today.

Second,
Smart developers/ businesses (I think most ZC developers) gives away scarcity to sell the even more scarce resource more often. What I mean by this...A good developer understands that by giving away some scarcity  (knowledge, open source app, resources, tips), he increases his following, professional position, client trust, etc. This leads to the sale of more of the most scarce resource. This would be a developers billable time.

Do you think that a person like Gaev is getting less business because he has over 1200 ZC posts? Many of these posts are him helping other developers like me AND new beginners just learning to declare a variable. No, he is definitely not getting less business.

Let's take this to a more macro level. John Resig, creator of jQuery. I think it's safe to say that he is making more money now after giving away, creating jQuery then he would have keeping this tool to himself and sharing it with only his clients or his employer Mozilla. Don't you think? I know this is sort of a ridiculous example. But it gets my point across.

I think that Gaev and other ZC developers alike have learned to take the broader view in regards to getting ZC jobs. By all of us adding a wealth of content to the forums the Zoho Creator products grows in popularity which in turns brings more business to all the developers. Yes, I am sure there are times where a new developer that hasn't "paid his dues" gets a "Marketplace" project when maybe he isn't the best developer for the job. But, most savvy prospects can review work and see ZC forum posts to discern who's right for the job.

Zoho Creator has invested much time, money, resources into creating a "one stop shop" for Zoho Creator. ZC apps, wiki, forum, marketplace - these are all a click away. For this reason the opportunity cost for a developer to share his Zoho Creator knowledge isn't as high.

In contrast a Web Designer/Developer on his own would need a strong presence on many job boards, a nicely setup blog with tons of traffic from potential clients, a group of Twitter users (who have their own target audience) periodicially RT'ing your good ZC forum posts, as well as many other intangible assets.

Here's how I think the Zoho Creator community is setup.

 The first group of people are DIY'ers. They are almost always NOT a developer working for/as a development company. They are simply men and women looking to solve a business problem. They ARE NOT competition for developers and are sometimes future business! So it makes sense to help them. Many of them are the type who will NEVER use a developer and THIS IS OK TO ME. However, on many of my Zoho Creator poject starts the first 10 minutes of the conversation is about the Zoho Creator application they started but got stuck somewhere on.

The second group of people on the forums are people who are "kicking the tires" of Zoho Creator to get an idea about Zoho Creator's capabilities. They might be an employee or IT worker for a business.  These people are SOON TO BE OR FUTURE BUSINESS AS WELL. These are the sort of people we as third party developers need to engage with a lot to show/ convince them of how Zoho Creator can solve their problems.

The third group is the developer community.. They help other DIY'ers, "tire kickers", and other developers with their projects.

Stephen Rhyne
Owner
Rhyne Design
@srhyne

Comments [0]

Zoho Creator Map Function (Advanced)

 This is a follow up post to the following two other posts....

1. Map Tutorial (Beginners)

2. Map Tutorial (Intermediate) 

In this post I am going to talk about some more advanced ideas concepts in regards to using maps and lists together.

If you are reading this you are already aware of the power of using lists and maps together to create powerful DS scripts.


I'm going to cover HOW TO COMBINE A ZC MAP AND A ZC LIST TO CREATE MULTI-DIMENSIONAL ARRAYS( Think form records stored in script format).

In PHP it's very easy to create a multi-dimensional array (many map variables inside a big list) and encode

this into JSON... A PHP multidimensional associative array looks like this....

$client_array = array(

     "client_address"=>array(

       "street"=>"PO Box 1000",

        "city"=>"Seattle",

         "state"=>"WA",

          "zip"=>"98122"

      ),

     "contact_info"=>array(

     "mobile"=>"555-1212",

      "email"=>"john@acme.com"

     )

);

In the above PHP example the $client_array would be a ZC Deluge Script list() where list.size() == 2.

the client_address and client_info arrays would be ZC Deluge Script map()'s


Stephen, Why would I want to make a multi-dimensional array in Zoho Creator? 

1. Store records in script format to be added to a new application upon loading it for the first time. (instead of XML or a getURL() call)

2. Convert cumbersome XMLList()'s to an easy list/map format...

Replace  _.executeXPath("/row/blah/blah/text()"); with a simple map.get("key"); 

NOTE: Try executing an XPath on an xmlList you called through a function! Your Xpath variable will come back null! This solves that problem/bug. (Let me know if you have solved this issue in the past.)

3. Store huge amounts of structured records data IN a variable to be looped through later. 


Reason for coming up with this idea.

Recently I have been doing a lot of Zoho Creator API work with PHP & jQuery/Javascript coding using the JSON feed instead of XML... and I LOVE IT!

JSON is such a great data format and it's so easy to traverse over/iterate through the records in JSON..

Example: Traversing over JSON in Javascript

for (i = 0; i < length; i++) {
                    var name = suppliers[i].name;
                    var address = suppliers[i].address;
                    var zoho_id = suppliers[i].zoho_id;
                    });

Now back to Zoho Creator Maps! Zoho Creator Maps ARE VALID JSON when you output them to string..

But, at first I was completely unable to traverse over ZC Maps like you do in regular scripting (like the above JS example).

If you have noticed there is no "for each" option in the map manipulations on the script builder menu AND there isn't really a clear cut way to store key,value pairs in a regular list. (You could mess with indexes or create text deliminators and stuff but it's sort of a bad way of doing things.)

So I tried putting map() variables inside a list. This way I could store my maps inside a format that Zoho Creator permits looping.

If you try to put a map() variable inside a list this is what you get.......

Error at line : 13
Unsupported type given as argument

BUT! What if you convert your map variable to a STRING! Then your list is just holding text (text that is perfectly willing to be converted back into a map later AND is perfectly willing to be saved in a list!)

Let's look at an example of how we can create a MULTI-DIMENSIONAL ARRAY in Zoho Creator....


Creating a multi-dimensional array in Zoho Creator

list test.array_encode()
{
    start_list = {"node1", "node2", "node3", "node4"};
    end_list = List();
    for each r in start_list
    {
        map = map();
        map.put("field1", 1);
        map.put("field2", 2);
        map.put("feild3", 3);
        map.put("field4", 4);
        stringMap = map;
        end_list.add(stringMap.toString());
    }
    test_list = list();
    for each test in end_list
     {
         map = test.toMap();
         test_list.add(map.get("field1"));   
     }
    info test_list;
    return end_list;
}


1. We created a function that returns a list

list test.array_encode()
{}

2. We created a "start_list" with node1 through node 4. 

    start_list = {"node1", "node2", "node3", "node4"};

 The nodes are simply a list telling us how many iterations we are going to have. This could instead be a collection list of records or rows in an XML list perhaps.

3. Now we create an "end_list" this list will hold our key/value pairs (created by the map function).

end_list = List();

In our PHP example the end_list would be the $client_array variable and the "r" variable in the loop would be each
array inside the $client_array (separated by commas).

4. We create a new map, PUT our keys and values into the map, then convert it to a string!

map = map();
        map.put("field1", 1);
        map.put("field2", 2);
        map.put("feild3", 3);
        map.put("field4", 4);
        stringMap = map;
        end_list.add(stringMap.toString());

OUTPUT FROM HERE!

  1.  
    [{"field4":4,"feild3":3,"field1":1,"field2":2}, {"field4":4,"feild3":3,"field1":1,"field2":2}, {"field4":4,"feild3":3,"field1":1,"field2":2}, {"field4":4,"feild3":3,"field1":1,"field2":2}]
5. LET'S TEST IT!

    test_list = list();
    for each test in end_list
     {
         map = test.toMap();
         test_list.add(map.get("field1"));   
     }
    info test_list;

Here we create a "test_list" to grab our "values" from the array. We create a new map variable "map" then convert the map string BACK INTO A MAP. Then we just add the the map value to our list and "debug/Info" the test_list..

SURE ENOUGH THE "test_list" comes back with

1, 1, 1, 1

ISN'T THAT GREAT! If you start to think about it more you will see the similarities to the "for each record" function

but instead of using form field names to get your value you use the map's key value!



I hope you find great use out of this concept! Soon I will be posting some more ways to incorporate it into your DS scripts LIKE converting XML to ZC arrays without mapping hundreds of XPaths, storing many records inside ONE record, etc.

PLEASE let me know if you have ideas or suggestions on how to make this concept better. I am always open to ideas. If you have any questions you can go to my website, or post it here as a comment on the forum.

Stephen Rhyne
Owner
Rhyne Design

Filed under  //   Deluge Script   JSON   Map Function   Zoho   Zoho Creator  

Comments [0]