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

Cannot select Placeholder field #449

Open
realenginerd opened this issue Apr 19, 2016 · 2 comments
Open

Cannot select Placeholder field #449

realenginerd opened this issue Apr 19, 2016 · 2 comments

Comments

@realenginerd
Copy link

I have a form where one of the fields is a "multiple choice":

var key: Key?
private var keys: [Key]

func keyField() -> [String: AnyObject]
{
    let form: [String: AnyObject] = [
        FXFormFieldPlaceholder: "No key",
        FXFormFieldOptions: smartkeys!
    ]

    if let nonNilKey = key
    {
        form[FXFormFieldDefaultValue] = nonNilKey
    }

    return form
}

The form appears correctly. "No key" appears at the top of the list, and is selected (marked with a check mark) if key is nil. When I click on a different key, it gets assigned to key correctly, and the check mark migrates accordingly.

When I try to click back on "No key", however, nothing happens. The (placeholder) cell is briefly highlighted, but the check mark does not migrate. The 'key' field still contains the old value, and does not get reset to nil. What should I do to get it to work this way? Is this supported in FXForms?

@realenginerd
Copy link
Author

Further observation: seems as though Placeholder and Default Value doesn't work well together; I can only get one or the other. I can select the Placeholder with no problems if there is no Default Value specified. However, if I cannot specify a Default Value, the form does not get populated correctly.

On the other hand, if a Default Value is specified, the opposite problem occurs: the form shows up correctly -- default value is selected -- but I cannot select the Placeholder.

Am I holding this wrong? Is there a way to make this work? Please advise. Thanks in advance!

@coybit
Copy link

coybit commented Apr 15, 2017

I have solved this problem by adding

if ([value unsignedIntegerValue] == NSNotFound) return nil;

to 'value' getter:

- (id)value
{
    if (FXFormCanGetValueForKey(self.form, self.key))
    {
        id value = [(NSObject *)self.form valueForKey:self.key];
        if (value && self.options)
        {
            if ([self isIndexedType])
            {
                if ([value unsignedIntegerValue] == NSNotFound) return nil;
                if ([value unsignedIntegerValue] >= [self.options count]) value = nil;
            }
            else if (![self isCollectionType] && ![self.type isEqualToString:FXFormFieldTypeBitfield])
            {
                //TODO: should we validate collection types too, or is that overkill?
                if (![self.options containsObject:value]) value = nil;
            }
        }
        if (!value && self.defaultValue)
        {
            self.value = value = self.defaultValue;
        }
        return value;
    }
    return self.defaultValue;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants