Opened 8 years ago

Closed 8 years ago

Last modified 7 years ago

#13433 closed defect (fixed)

set regExp on running time

Reported by: weezero Owned by: Douglas Hays
Priority: high Milestone: 1.8
Component: Dijit - Form Version: 1.6.1
Keywords: Cc:
Blocked By: Blocking:

Description (last modified by bill)

when i set the regExp on running time doesn´t seem to work equal of when i set the regExp on control´s creation, i mean, the result is the same but the control´s behaviour seems different.

i have these controls:

  • ipt_tipo_telefono: FilteringSelect,
  • ipt_codigo_area: ValidationTextBox and
  • ipt_numero_telefono: ValidationTextBox (on this one i set the regExp according to the values of the other two)

On onChange event of the first two, execute this function:

function validarTelefono()
{
	var codigo_area = dijit.byId("ipt_codigo_area").get("value");
	var tipo_telefono = dijit.byId("ipt_tipo_telefono").get("value");
	var ipt_numero_telefono = dijit.byId("ipt_numero_telefono");
	

	if (tipo_telefono.substr(0,3)=="Par")
	{		


		var long_telefono = 11 - codigo_area.length;
		ipt_numero_telefono.set("maxLength", long_telefono);
		ipt_numero_telefono.set("promptMessage","");

		if (codigo_area=="011")
		{
			ipt_numero_telefono.set("regExp","\\b[3-6]\\d{" + (long_telefono - 1) 
+ "}\\b");
		}

		else
		{
			ipt_numero_telefono.set("regExp","\\b[4-5]\\d{" + (long_telefono - 1) 
+ "}\\b");
		}

	}
	else
	{
		if (tipo_telefono.substr(0,3)=="Cel")
		{

			var long_telefono = 13 - codigo_area.length;
			ipt_numero_telefono.set("maxLength", long_telefono);
			ipt_numero_telefono.set("promptMessage","No olvide anteponer el 15.");
			
			ipt_numero_telefono.set("regExp","\\b15[4-6][0-9]{" + (long_telefono 
- 3) + "}\\b");

		}
	}
	
}

Attachments (2)

13433.patch (20.6 KB) - added by Douglas Hays 8 years ago.
deprecate regExpGen and recompute the validating RE after regExp is changed
13433.2.patch (21.1 KB) - added by Douglas Hays 8 years ago.
deprecate regExp and regExpGen in favor of HTML5's pattern

Download all attachments as: .zip

Change History (8)

comment:1 Changed 8 years ago by bill

Component: GeneralDijit - Form
Description: modified (diff)
Owner: set to Douglas Hays

You'll need to be more specific about what problem you are seeing (explaining the expected behavior vs. the actual behavior), and also attach a full test case (a single HTML file with instructions on how to run and reproduce the problem), thanks.

comment:2 Changed 8 years ago by Douglas Hays

Milestone: tbd1.8

regexp needs a custom _set*Attr method to recompute the generated partialre value, but this is complicated by the regExpGen method which should be deprecated and combined with regExp since both cannot be specified. I'll target this for 1.8 for now. It should be possible to regen the partialre internal value by calling
widget.set('constraints', widget.get('constraints'));
Of course without a comment as to what bad thing is happening currently, this problem may or may not be fixed by this enhancement.

comment:3 Changed 8 years ago by weezero

the expected behavior of the regExp is until you don´t type an invalid character, the control doesn´t marked as invalid, but when i set the regExp attribute on running time, the actual behavior is that the control shows an invalid state while you are typing (even if its valid) until you finish typing, then it marked as valid. i hope you understand me, pardon my english

Changed 8 years ago by Douglas Hays

Attachment: 13433.patch added

deprecate regExpGen and recompute the validating RE after regExp is changed

comment:4 Changed 8 years ago by Douglas Hays

weezero, can you test with the attached patch?

Changed 8 years ago by Douglas Hays

Attachment: 13433.2.patch added

deprecate regExp and regExpGen in favor of HTML5's pattern

comment:5 Changed 8 years ago by Douglas Hays

Resolution: fixed
Status: newclosed

In [28064]:

Fixes #13433. Change ValidationTextBox?'s regExp/Gen to use HTML 5's pattern attribute instead.

comment:6 Changed 7 years ago by bill

In [30576]:

If ValidationTextBox.pattern is a function, then ValidationTextBox.get("pattern") should return that function, rather than the result of the function. Also, _setRegExpGenAttr() should use this._set() to save the value. Refs #13433, #16693 !strict.

Note: See TracTickets for help on using tickets.