setting HTML custom attributes from javascript

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

User avatar
dvanhussel
Ebase User
Posts: 161
Joined: Fri Oct 19, 2007 12:45 pm
Location: Haarlem, the Netherlands

setting HTML custom attributes from javascript

#1

Postby dvanhussel » Thu Feb 28, 2013 9:23 am

Hi,

I was wondering if it is possible to set/read the value of the HTML custom attributes of a form field.
An example of what I want to do:

Code: Select all

   var fieldName = ctrl.field;
   var helpText = fieldName.helpText.text;
I would like to add the contents of 'helpText' to the HTML custom property Title of a control.

I could not find a way to do this in the manual.

Regards,

David
0 x

dan
Ebase User
Posts: 8
Joined: Mon Jan 14, 2013 9:49 am

#2

Postby dan » Thu Feb 28, 2013 3:10 pm

Hi there,

I think what you are asking here is that how do make the 'title' attribute of the editor of a Field Control to be whatever you have set that control's help text to be. This will then mean that this is popped up when the editor is hovered over with the mouse.

There isn't a direct way to perform this in Ebase Xi. Although Custom Attributes offer a way of overriding 'normal' html attributes such as the title attribute, this is more of a side-effect of their intended purpose which is to provide a way to make use of libraries which dictate the use of specific attributes in order to perform some action on them (for example the jQuery mobile and jQueryUI framework libraries).

Really what there should be is a way to specify a title as a property of the Field Control (as well as any others that might be appropriate) and allowing that to be set dymanically in the same way as the majority of properties of a control are. I think that this is something we will look into doing as an enhancement in the future.

This doesn't really help you now, however.

There is a way of doing this using jQuery however, which may, or may not be appropriate depending on the form you are designing.

Here is a general approach to acheiving this (if you only want 1 Field Control to behave like this there are more precise methods to use, but this will still work).

This assumes that you are aware of Client Scripts in Ebase Xi, if not have a look at:

http://dev-docs.verj.io/ufs/doc/Creatin ... lients.htm
http://dev-docs.verj.io/ufs/doc/Creatin ... y_Step.htm (there is a useful section about setting up jQuery as a client script here, which you will need to do if you haven't already).

1. Add the help text to any Field Controls you want this to affect as normal and set the 'Help text position' property of them to: 'To right of editor'.

2. In the HTML Properties of the Field Control(s) in question add 'changeTitleToHelp' to the Class Locator and press OK. Only those Field controls with this Class Locator will be affected.

3. Go to the Ebase Xi Designer Tree go to the Web Resources Folder, right-click and select add new->Client Script.
3.1. Name this script (does matter what), copy the following into it and press OK.

Code: Select all

	function setFieldTitlesToHelpText($, showhelpText)
	{
		var fieldsToTitle = $('.changeTitleToHelp');
	
		for&#40;var i = 0; i < fieldsToTitle.length; i++&#41;
		&#123;
		  		// the help of the field control must be set to display in the designer
					//  or things will go very wrong
					var help = $&#40;fieldsToTitle&#91;i&#93;&#41;.find&#40;'div'&#41;.last&#40;&#41;;

					if&#40;!showhelpText&#41;
					&#123;
							$&#40;help&#41;.css&#40;'display', 'none'&#41;;
					&#125;
	
					$&#40;fieldsToTitle&#91;i&#93;&#41;.find&#40;'input,textarea,select'&#41;.attr&#40;'title', $&#40;help&#41;.text&#40;&#41;&#41;;
		&#125;
	&#125;
4. Go to Form Properties, click on the Web Resources Tab and click on the ... button by the Client Scripts section.
4.1 Add the jQuery library as an External Client Script (see http://dev-docs.verj.io/ufs/doc/Creatin ... y_Step.htm)
4.2 Add the Client Script we created in step 3.
4.3 Make sure the jQuery External Client Script is at the top the list before pressing OK.

5. Right Click on the Page Control and select HTML Properties.
5.1 Select the jQuery Tab and choose the 'ready' Event.
5.2 Now click on the ... button in the code section and add the following line:

Code: Select all

     setFieldTitlesToHelpText&#40;$, false&#41;;
5.3 Press OK to that and then again to exit the HTML Element Properties dialog.

6. Run the form. If all is configured correctly then your fields should show, the help text will have been hidden and the title attribute of the field controls editor will be changed to the help text (and appears when the mouse hovers over the input).


A big limitation to this method is that the Help Text must be displayed 'to the right of the editor' or the title will be set to blank, and this method may also have some impact when it comes to styling these fields (particularly when they are in a field layout), but that depends on your styling choices.

Hope this is some help to you - there is an example form here, which you can import to see this in action.
0 x
Dan

User avatar
dvanhussel
Ebase User
Posts: 161
Joined: Fri Oct 19, 2007 12:45 pm
Location: Haarlem, the Netherlands

#3

Postby dvanhussel » Fri Mar 01, 2013 8:53 am

Hi Dan,

Thank you for your very detailed answer. This is exactly what I was trying to achieve. I would like the changes to Ebase Xi which you mention.

But for now, I looked in to using your 'work around'.

It looks promising to me, except, that I would like to keep the question mark image as well.
But maybe, the client thinks that it is ok to just show the help text when hovering over the field.

However, there seems to be a problem with your solution if Immediate Validation is set on the field. Then, when the field is changed, the helptext becomes visible on the right again.

Is this one of the drawbacks that you mentioned in your post (this also happens in your example when I set immediate validation)? Or is it maybe related to a bug, on validation on the server the following is logged: ERROR Failed to serve JQueryEventRegistration - unable to find running form.

I see this on every form when immediate validation is run, so I will submit a bug report for it.
0 x

dan
Ebase User
Posts: 8
Joined: Mon Jan 14, 2013 9:49 am

#4

Postby dan » Fri Mar 01, 2013 10:03 am

Hi,

Code: Select all

function setFieldTitlesToHelpText&#40;$, showhelpText&#41;
&#123;
		var fieldsToTitle = $&#40;'.changeTitleToHelp'&#41;;
	
		for&#40;var i = 0; i < fieldsToTitle.length; i++&#41;
		&#123;
		  		// the help of the field control must be set to display in the designer
					//  or things will go very wrong
					var help = $&#40;fieldsToTitle&#91;i&#93;&#41;.find&#40;'div'&#41;.last&#40;&#41;;
					var helptext;
					// is this a pop-up help?
					var popup = $&#40;help&#41;.children&#40;'input'&#41;;
					if&#40;popup == null || popup == undefined || popup.length == 0&#41;
					&#123;
							helptext =  $&#40;help&#41;.text&#40;&#41;;
					&#125;
					else
					&#123;
							helptext = $&#40;popup&#41;.val&#40;&#41;;
					&#125;

					if&#40;!showhelpText&#41;
					&#123;
							$&#40;help&#41;.css&#40;'display', 'none'&#41;;
					&#125;
	
					$&#40;fieldsToTitle&#91;i&#93;&#41;.find&#40;'input,textarea,select'&#41;.attr&#40;'title', helptext&#41;;
		&#125;
&#125;
Replace the code in your client script with the code above and you can either set the Help Text Position property as 'To right of editor' or 'As popup window'.

To keep all the help ? or texts visible then right-click on the Page Control, open HTML Element Properties and change the code of the jQuery ready event so that it says true instead of false:

Code: Select all

setFieldTitlesToHelpText&#40;$, true&#41;;
That should do it.

The ERROR Failed to serve JQueryEventRegistration - unable to find running form is a known problem which we will fix in a service pack in the next few days. This is the reason you are seeing the problems when immediate validation is turned on and its not a limitation/drawback of this method.
0 x
Dan

User avatar
dvanhussel
Ebase User
Posts: 161
Joined: Fri Oct 19, 2007 12:45 pm
Location: Haarlem, the Netherlands

#5

Postby dvanhussel » Sat Mar 02, 2013 12:58 pm

Hi Dan,

Thanks again! :D

With this script and the latest service pack installed it works.

I added the following code to the jQuery onclick event of 'info' to prevent the popup being displayed:

Code: Select all

e.preventDefault&#40;&#41;;
Now it has the exact behavior that our client asked for.

A nice side effect of using the question mark, is that you don't see the help text displayed very briefly on page refresh.
0 x


Who is online

Users browsing this forum: No registered users and 40 guests