Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Store the parent form of fields to allow nesting forms. #1

Merged
merged 3 commits into from
Jul 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions Assets/Plugins/CandyCoded.Forms/Scripts/Form.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,18 @@ private void Update()

}

public IEnumerable<FormField> GetChildFormFields()
{

return gameObject.GetComponentsInChildren<FormField>()
.Where(field => field.name != "" && field.parentForm.Equals(this));

}

public Dictionary<string, object> GetFormRawValues()
{

return gameObject.GetComponentsInChildren<FormField>().Where(field => field.name != "")
.ToDictionary(field => field.name, field => field.value);
return GetChildFormFields().ToDictionary(field => field.name, field => field.value);

}

Expand All @@ -74,7 +81,7 @@ public Dictionary<string, object> GetFormRawValues()
public void LoadFormRawValues(Dictionary<string, object> values)
{

var formFields = gameObject.transform.GetComponentsInChildren<FormField>();
var formFields = GetChildFormFields();

foreach (var value in values)
{
Expand All @@ -98,7 +105,7 @@ public void LoadFormRawValues(Dictionary<string, object> values)
public void LoadFormValues<T>(T values)
{

var formFields = gameObject.transform.GetComponentsInChildren<FormField>();
var formFields = GetChildFormFields();

foreach (var fieldInfo in values.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance))
{
Expand Down
9 changes: 9 additions & 0 deletions Assets/Plugins/CandyCoded.Forms/Scripts/FormField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class FormField : MonoBehaviour

private object _value;

public Form parentForm { get; private set; }

public new string name
{
get
Expand Down Expand Up @@ -106,6 +108,13 @@ public object value
}
}

private void Awake()
{

parentForm = gameObject.GetComponentInParent<Form>();

}

public void SetStringValue(string value)
{

Expand Down