Beispiel #1
0
        /// <summary>Resets this form.</summary>
        public void reset()
        {
            // Dispatch the reset event:
            FormEvent de = new FormEvent("reset");

            de.SetTrusted(true);
            // Hook up the form element:
            de.form = this;

            if (dispatchEvent(de))
            {
                // Get resettable elements:
                HTMLFormControlsCollection allReset = GetAllInputs(InputSearchMode.Submittable);

                foreach (Element e in allReset)
                {
                    HtmlElement he = (e as HtmlElement);

                    if (he != null)
                    {
                        he.OnFormReset();
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>Gets all input elements contained within this form.</summary>
        /// <param name='mode'>The form search options.</summary>
        /// <returns>A list of all input elements.</returns>
        public HTMLFormControlsCollection GetAllInputs(InputSearchMode mode)
        {
            HTMLFormControlsCollection results = new HTMLFormControlsCollection();

            GetAllInputs(results, this, mode);
            return(results);
        }
Beispiel #3
0
        public HTMLFormElement()
        {
            Init("FORM");

            Elements = new HTMLFormControlsCollection();
            OnReset  = new DOMEventHandler <HTMLFormEventReset>(this);
            OnSubmit = new DOMEventHandler <HTMLFormEventSubmit>(this);
        }
Beispiel #4
0
        /// <summary>Submits this form using the given button. It may override the action etc.</summary>
        public void submit(HtmlElement clickedButton)
        {
            // Generate a nice dictionary of the form contents.

            // Step 1: find the unique names of the elements:
            Dictionary <string, string> uniqueValues = new Dictionary <string, string>();

            // Get submittable elements:
            HTMLFormControlsCollection allInputs = GetAllInputs(InputSearchMode.Submittable);

            foreach (Element element in allInputs)
            {
                if (element is HtmlButtonElement)
                {
                    // No buttons.
                    continue;
                }

                string type = element.getAttribute("type");
                if (type == "submit")
                {
                    // No submit either.
                    continue;
                }

                string name = element.getAttribute("name");
                if (name == null)
                {
                    name = "";
                }

                // Step 2: For each one, get their value.
                // We might have a name repeated, in which case we check if they are radio boxes.

                if (uniqueValues.ContainsKey(name))
                {
                    // Ok the element is already added - we have two with the same name.
                    // If they are radio, then only overwrite value if the new addition is checked.
                    // Otherwise, overwrite - furthest down takes priority.
                    if (element.Tag == "input")
                    {
                        HtmlInputElement tag = (HtmlInputElement)element;

                        if (tag.Type == InputType.Radio && !tag.Checked)
                        {
                            // Don't overwrite.
                            continue;
                        }
                    }
                }
                string value = (element as HtmlElement).value;
                if (value == null)
                {
                    value = "";
                }
                uniqueValues[name] = value;
            }

            // Get the action:
            string action = GetOverriden("action", clickedButton);

            FormEvent formData = new FormEvent(uniqueValues);

            formData.SetTrusted(true);
            formData.EventType = "submit";
            // Hook up the form element:
            formData.form = this;

            if (dispatchEvent(formData))
            {
                // Get ready to post now!
                DataPackage package = new DataPackage(action, document.basepath);
                package.AttachForm(formData.ToUnityForm());

                // Apply request to the data:
                formData.request = package;

                // Apply load event:
                package.onload = package.onerror = delegate(UIEvent e){
                    // Attempt to run ondone (doesn't bubble):
                    formData.Reset();
                    formData.EventType = "done";

                    if (dispatchEvent(formData))
                    {
                        // Otherwise the ondone function quit the event.

                        // Load the result into target now.
                        string target = GetOverriden("target", clickedButton);

                        HtmlDocument targetDocument = ResolveTarget(target);

                        if (targetDocument == null)
                        {
                            // Posting a form to an external target.

                            Log.Add("Warning: Unity cannot post forms to external targets. It will be loaded a second time.");

                            // Open the URL outside of Unity:
                            UnityEngine.Application.OpenURL(package.location.absoluteNoHash);
                        }
                        else
                        {
                            // Change the location:
                            targetDocument.SetRawLocation(package.location);

                            // History entry required:
                            targetDocument.window.history.DocumentNavigated();

                            // Apply document content:
                            targetDocument.GotDocumentContent(package.responseText, package.statusCode, true);
                        }
                    }
                };

                // Send now!
                package.send();
            }
        }
Beispiel #5
0
 void IDisposable.Dispose()
 {
     this.htmlCollectionCollection = null;
 }
Beispiel #6
0
 public ElementEnumerator(HTMLFormControlsCollection collection)
 {
     this.htmlCollectionCollection = collection;
     this.htmlCollectionCount      = this.htmlCollectionCollection.Length;
     this.htmlCollectionIndex      = -1;
 }
Beispiel #7
0
 /// <summary>
 /// Creates a new HTML form element.
 /// </summary>
 internal HTMLFormElement()
 {
     _name     = Tag;
     _elements = new HTMLFormControlsCollection();
 }
Beispiel #8
0
 /// <summary>
 /// Creates a new HTML form element.
 /// </summary>
 internal HTMLFormElement()
 {
     _cancel   = new CancellationTokenSource();
     _name     = Tags.Form;
     _elements = new HTMLFormControlsCollection(this);
 }