Permalink
Browse files

demo funcional do autocomplete

  • Loading branch information...
1 parent 066e6f7 commit 2b7ad68b9e815e107c1f61fb321bd64f83ab094b @sikora sikora committed Mar 2, 2011
Showing with 33 additions and 10 deletions.
  1. +4 −1 index_autocomplete.html
  2. +8 −1 xsdForm-ui.js
  3. +21 −8 xsdForm.js
View
@@ -22,7 +22,9 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>xsdFormJs</title>
- <link href="style.css" rel="stylesheet" type="text/css"></link>
+ <link href="style.css" rel="stylesheet" type="text/css"></link>
+ <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.8/themes/base/jquery-ui.css" type="text/css" media="all" />
+
</head>
<body
@@ -37,6 +39,7 @@
<textarea name="processed_xml" rows="20" cols="100"></textarea>
</form>
<script src="jquery-1.4.4.js" type="text/javascript"></script>
+ <script src="jquery-ui-1.8.10.custom.min.js" type="text/javascript"></script>
<script src="input.deflate.plugin.js" type="text/javascript"></script>
<script src="jquery.meio.mask.js" type="text/javascript"></script>
<script src="xsdForm.js" type="text/javascript"></script>
View
@@ -234,5 +234,12 @@ function generateXsdFormUI() {
$('input.xsdForm__integer').regexMask('integer');
+ $('input.autoComplete').each(
+ function(i,elemento) {
+ $(this).autocomplete({
+ source: $(elemento).attr('rel'),
+ minLength: 2
+ });
+ });
-}
+}
View
@@ -18,16 +18,13 @@
# Fundação do Software Livre(FSF) Inc., 51 Franklin St, Fifth Floor,
*/
-function createInput(type, name, id, maxlength, restrictionNode) {
+function createInput(type, name, id, maxlength) {
var newInput = document.createElement('input');
newInput.type = type;
newInput.name = name;
if (maxlength != null) {
newInput.setAttribute('maxlength', maxlength);
}
- if (restrictionNode.getAttribute('base') == 'autocomplete') {
-
- }
newInput.id = ( id != undefined )? id: name;
return newInput;
}
@@ -411,14 +408,16 @@ function generateXmlFromComplexTypeNodeNoRepeat(odoc, namespace, tagRaiz, xmlNod
function generateFormFromSimpleTypeNode(tagRaiz, xmlNode, namePattern, name, label, minOccurs) {
var restrictionNode = getNodeByTagName(xmlNode, 'xs:restriction');
+ var engine = getValueAttributeByName(xmlNode, "engine");
+ var service = getValueAttributeByName(xmlNode, "service");
for (var i = 0; i < restrictionNode.childNodes.length; i++) {
if (restrictionNode.childNodes[i].nodeType == 1 && restrictionNode.childNodes[i].nodeName == 'xs:pattern' ) {
return generateFormFromSimpleTypeNodeRestrictionPattern(tagRaiz, xmlNode, namePattern, name, label, minOccurs,restrictionNode.childNodes[i].getAttribute('value') );
} else if (restrictionNode.childNodes[i].nodeType == 1 && restrictionNode.childNodes[i].nodeName == 'xs:enumeration' ) {
return generateFormFromSimpleTypeNodeRestrictionEnumeration(tagRaiz, xmlNode, namePattern, name, label, minOccurs);
} else if (restrictionNode.childNodes[i].nodeType == 1 && restrictionNode.childNodes[i].nodeName == 'xs:maxLength' ) {
- return generateFormFromSimpleTypeNodeRestrictionMaxLength(tagRaiz, xmlNode, namePattern, name, label, minOccurs,restrictionNode.childNodes[i].getAttribute('value'),restrictionNode);
+ return generateFormFromSimpleTypeNodeRestrictionMaxLength(tagRaiz, xmlNode, namePattern, name, label, minOccurs,restrictionNode.childNodes[i].getAttribute('value'), engine, service );
} else if (restrictionNode.childNodes[i].nodeType == 1 && restrictionNode.childNodes[i].nodeName == 'xs:fractionDigits' ) {
return createFieldDecimal(namePattern, name, label);
}
@@ -483,17 +482,31 @@ function generateFormFromSimpleTypeNodeRestrictionPattern(tagRaiz, xmlNode, name
return frag;
}
-function generateFormFromSimpleTypeNodeRestrictionMaxLength(tagRaiz, xmlNode, namePattern, name, label, minOccurs, maxLength, restrictionNode){
+function generateFormFromSimpleTypeNodeRestrictionMaxLength(tagRaiz, xmlNode, namePattern, name, label, minOccurs, maxLength, engine, service){
var inputName = namePattern + "__" + name;
+
var newLabel = document.createElement("label");
newLabel.innerHTML = label;
newLabel.htmlFor = inputName;
var dt = document.createElement('dt');
var dd = document.createElement('dd');
dt.appendChild(newLabel);
- dd.appendChild(createInput('text' ,inputName, inputName, maxLength, restrictionNode));
+ field = createInput('text' ,inputName, inputName, maxLength);
+
+ if (engine) {
+ if (field.getAttribute('class')) {
+ field.setAttribute('class', field.getAttribute('class')+ ' '+ engine)
+ } else {
+ field.setAttribute('class', engine)
+ }
+ field.setAttribute('rel', service);
+ }
+
+ dd.appendChild(field);
+
+
var frag = document.createDocumentFragment();
frag.appendChild(dt);
@@ -515,7 +528,7 @@ function generateXmlFromSimpleTypeNode(odoc, namespace, tagRaiz, xmlNode, namePa
var node = xmlNode.childNodes[i];
if (node.nodeType == 1) {
if (node.nodeName == "xs:restriction" &&
- node.getAttribute('base') == "xs:string" || node.getAttribute('base') == 'autocomplete') {
+ node.getAttribute('base') == "xs:string") {
restriction = node;
} else {
throw "Unkown simple type";

0 comments on commit 2b7ad68

Please sign in to comment.