Wednesday, March 23, 2011

Client-side Form Validation using jQuery Mobile

Lately, I've been involved in a project which is mainly targeting mobile browsers. The decided to use kinda "new" jQuery mobile "library". jQuery Mobile is a ……built over jquery, css, js, multiple browser support, etc…… It's still in beta? Yet, it renders pretty fine, and we didn't have more than a couple of issues with it. But it save us loads of time rendering on a nice range of supported mobile browsers.

For eg, I stepped into a problem with client-side validation lately. When jQuery Mobile renders input of type submit (i.e. a submit button for a form), it actually hides the "input" tag, and replace it with an anchor? (ie "a" tag).

Say, you want to add function to handle "onclick" event, validate the form, before hitting the server-side, and prevent it from submitting if it failed; something like:

<input type="submit" onclick="return ValidateForm()" />

The  function is actually never called because the actual input tag is as jQuery Mobile hides and replaces it by an anchor.

Adding the validation function via js/jquery after the document is ready to the anchor, will allow you to call it on clicking the anchor. Yet, it won't stop the form being submitted.

A nice alternative, is to use an input tag of type button, that is:

 <input type="button" onclick="ValidateForm();" />

And submit the form inside the function handling "onclick", rather than returning true/false, like:

   1:  function ValidateOwnerId() {                
   2:      if (/*form is valid*/) {
   3:          $('#myForm').submit(); // Submit from
   4:      }
   5:      else//not valid
   6:      {
   7:          /*show some error message without submitting form*/
   8:      }
   9:  }

Friday, March 18, 2011

الذين قالوا نعم و الذين قالوا لا

الإسبوع ده كان من أكتر الأسابيع المرهقة بالنسبة لي. مش بس عشان النقاشات(الأسعدتني جدا لانها أول مرة في حياتي تبقى بالشكل المفتوح/المتفتح ده) الغير منتهية عن تعديلات الدستور والاستفتاء. لأ كمان عشان كان من أكتر الأسابيع الكنت مضغوط فيها في الشغل  لدرجة إني -لأكثر من مرة- تقريبا "طردت" زملاء لي بيتناقشوا في نفس الموضوع من حوالين مكتبي عشان أشتغل :D

بسبب ضغط الشغل ده مكنتش متابع بشكل كافي الأحداث.. والإكتشفتها امبارح بليل والنهاردة وانا بحاول ألحق الفاتني.. كنت مبسوط معظم الإسبوع بالمقالات الكنت بقرأها في السريع عشان أحاول احدد هصوت بإيه في الإستفتاء.. كنت بحاول أقرأ لكتاب أرائهم من "المعسكرين" , نعم و لا, عشان أحاول  أكون رأيي الشخصي..

قرأت لعمرو حمزاوي و معتز عبدالفتاح و لكثيرين غيرهم, ده غير التحليل الوافي الذي قام به وائل خليل. اليوم أثار حفيظتي عدة أشياء.. معظم ماكنت اقرأه خلال الأسبوع كان محاولة لتحليل السيناريوهات المتوقعة لنعم و لا.. لكن فجأة اكتشفت إنه الموضوع تحول إلى استفتاء على دينك و وطنيتك!!

كنت سمعت خلال الإسبوع إنه بعض الأصوات في الكنيسة قالت للناس تصوت بلا.. بس لانشغالي و أسباب أخرى وضعت هذا الكلام في خانة الإشاعات. اليوم اكتشفت إنه كلام صحيح. سمعت أيضًا أن السلفيين والإخوان المسلمين كانوا بيدعوا الناس لنعم و اكتشفت حقيقة الكلام ده في صلاة الجمعة اليوم.. لدرجة اني قمت رحت اصلي في مسجد تاني لأكتشف إنه بيقول نفس الكلام.. أخيرًا شفت الفيديو لبعض المشاهير بيحاولوا يضغطوا به على مشاعر الناس عشان يقولوا لا.. واليحسس أي حد إنه مش مصري لو قال نعم

كل ده حسسني إنه الناس ديه مش محترمة عقلي ولا عقل المصريين بشكل عام. يعني بدل كل الناس ديه تدعوا الناس لانها تحكم عقلها و متضيعش حقها و تروح تصوت.. لأ بتقولهم ماتفكروش.. احنا فكرنا لكم والإجابة كذا!! كان أكرم للجميع في رأي لو طالبوا المصريين بالنزول للإستفتاء زي الفيديو الأصلي المأخوذ منه فكرة إعلان  قول لأ.

الأسعدني حقيقي إنه فيه ناس بتنادي بالمشاركة في الاستفتاء بس.. كمان بعد الصلاة ناس كتير كانت -على غير ما كنت أتوقع-  مش عاجبها استغلال الخطيب للخطبة.. ده غير إني اكتشفت كمان إنه كاتب ليه وزنه زي فهمي هويدي بيحذر من كلام مشابه. مش عاوزين يجي يوم نتكلم بنغمة شفيق: "أنا حضرت الثورة و هتفت و استشهدت" :D

Saturday, March 05, 2011

TEDx, El Sawy Culture Wheel, Bibliotheca Alexandrina, Open Brands, etc

I was having a chat with a friend, who is an enthusiast about community work, about that same topic (more specifically in Suez, my hometown) last week. Our conversation drove me to think about an idea that should have been done a little while ago (IMHO).

We all like the cultural "presence" of "organizations" like El Sawy Culture Wheel, and Bibliotheca Alexandrina. But unfortunately their effect is pretty local to where they exist. Another thing, similar organizations are too limited in resources, to reach out of their physical locations. They might try to expand vertically; creating more services, and enhancing them. But they almost never try to "branch out" in other places.

My idea for them is to spread their spirit/culture, share their experience with others who are willing to create similar experiences for their local communities, in a way similar to TEDx. Imagine if every city/governorate had their own Culture Wheel, which operate the same way, with the same spirit, but totally independent (financially for eg) on El Sawy's. Imagine instead of the usual bureaucratic "cultural palaces" (قصور الثقافة) there's a real cultural experience where people from all ages (specially youth) can find a decent place to mingle with like-minded people talking and sharing ideas, etc.

Thursday, March 03, 2011

"Note in (Google) Reader" issue Fix

Probably you're familiar with the sharing button (at least on Firefox and Chrome) offered by Google reader to help you share stuff that don't have feeds. Today, for some reason I realized that mine wasn't working!

GReader

 

After tweeting about it, thanks to Flavio Gomes and @mtobis, I realized what went wrong. Seems like the JavaScript file used by the button was updated, without updating the button script accordingly.

 

To solve this, all you have to do is set _IS_MULTILOGIN_ENABLED a variable that's not defined (but used) in the script file in the button script. So add something like:

_IS_MULTILOGIN_ENABLED=true;
// or
_IS_MULTILOGIN_ENABLED=false;
// or better
_IS_MULTILOGIN_ENABLED=((typeof(_IS_MULTILOGIN_ENABLED)=="undefined")?false:_IS_MULTILOGIN_ENABLED);

 

at the beginning of the button script, just to set _IS_MULTILOGIN_ENABLED before it's accessed as "undefined" in the script.

Sunday, January 09, 2011

How to force undo checkout? #TFS

Sometimes you'd pop into cases where you find yourself in a situation where you have to force undo pending code changes of someone else (say a colleague who is no more around, or even temporarily) or your own pending changes if say your machine (along with your workspace on it).

Well, there a Visual Studio tool for that.. That's tf command-line utility, which you can look for in your VS directory under Common7\IDE..

Using tf has lots and lots of uses, here's a really LONG list of them. Note: there's 3 sub-lists for VS2005, 2008, 2010. But for our tiny problem here, we mainly have to options, I'm using here the most straight forward ones:

Undoing pending changes for a specific file:

That will need mainly main parameters to start with: The name/path of the file checkout, User name (of the user who did the checkout), and the Workspace in which the checkout was done (usually your machine name if you didn't create an new workspace).

You could have an issue with the third one (workspace name), so you might have to check the Workspaces command for more details, but generally a small command like the one below will do just ok in most cases:

tf workspaces /owner:UserName

Knowing the above you can easily undo the pending changes as below, note: parameters are in squiggly braces like {these}:

tf undo {file path} /workspace:{workspace};{username} /server:{TFS name/IP}

Of course the "/server" part can be removed if you're on the same server running TFS. An example with some data will look like:

tf undo $/myProject/myFile.cs /workspace:mySpace;FCIH\shady /server:FCIH_TFS

Deleting the whole workspace:

The other option is to delete the whole workspace, which in turn delete any related checkouts. A simple command for that could be:

tf workspace /delete {workspace};{username} /server:{TFS name/IP}

which with some example parameters might look like:

tf workspace /delete Shady-PC;FCIH\shady /server:10.0.0.2

UPDATE:

After a comment by Meligy, I think I needed to add this: Most of the above needs you to be logged in as an account with TFS admin privileges, check the exact required permissions for Undo, Workspace and Workspaces commands.

If you're not logged in as the appropriate account, you can append {/login:username, [password]} to provide the authorized username and password.

Meligy, also, mentioned another tool called TFS Sidekicks that can do similar stuff.

Disclaimer

All the opinions expressed on this blog are my own and don't necessarily represent my employer's positions, strategies or opinions.