Biography field not recognized in datasource / manipulating number of fields
RyanKim01 opened this issue · comments
I have two issues. It would be great if you can quickly look over those, @3lvis .
(1) I made a custom field which is a subclass of BiographyCustomField class. I constructed it as same as one in demo. https://github.com/hyperoslo/Form/blob/db3769818dca71edd7d06d533f4e67a730c8ac45/CustomField/BiographyField.swift
The problem I'm facing is that Biography type of fields are not recognized in self.datasource.values.
I save self.datasource.values to my app to save the data user filled in Form. Oddly enough, whatever user writes in Biography field is not saved in self.datasource.values. Any thoughts?
(2) I have bunch of subtitle fields in my form. When I print "self.dataSource.numberOfFields" it also counts subtitle fields. I mean this is happening of course. But would there be a way to take out certain fields from numberOfFields? Lets say there are 3 text fields and 3 subtitle fields. I would just want to return 3 for self.dataSource.numberOfFields.
1.- This works as expected. Only "native" fields are returned on self.dataSource.values
, for custom values you have to manage their data by your own. In the demo, you could use BiographyFieldDelegate
and store changes every time the biography field gets changed.
2.- self.dataSource.numberOfFields
will return all the fields. The only way to get the fields that you want might be querying the section using FORMDataSource `
https://github.com/hyperoslo/Form/blob/master/Source/FORMDataSource.h#L227
/*!
* @param sectionID The identifier for the section.
* @return The found @c section, returns @c nil if the section is not found
*/
- (FORMSection *)sectionWithID:(NSString *)sectionID;
Then inside this section you can filter the fields that are subtitles.
Sorry this isn't simpler. I'm working so Form soon has better support for custom fields.
I hope this helps, otherwise just let me know.
@3lvis , I have further questions to ask you!
- I've successfully implemented what you said and it works. Right now, I'm persisting my data in a dictionary called "initialValues" and call that dictionary when I'm initializing a Form ViewController. However, it does not input the value as it does for other fields.
here is a json configuration:
{
"id": "part5_biography",
"type": "part5_biography",
"size": {
"width": 100,
"height": 2.0
}
}
and codes for initializing a FormVC:
initialValues = [
"part5_biography": "haha"
]
let sampleController = PartConfigurationViewController(JSON: JSON, initialValues: initialValues)
Not sure why "haha" value is not shown in textview in biography custom field when the VC is initialized.
Initial values also doesn't work with custom fields. You have to do it by yourself. You can probably do that using the callback
https://github.com/hyperoslo/Form/blob/master/Source/FORMDataSource.h#L27-L29
typedef UICollectionViewCell * (^FORMConfigureCellForItemAtIndexPathBlock)(FORMField *field,
UICollectionView *collectionView,
NSIndexPath *indexPath);
When field.fieldID == part5_biography
you can use the indexPath
to get the cell, and update the value of your textView
.
I will try to take in account initial values and self.dataSource.values
when improving support for custom fields in the future, sorry that you have to do so much manually this days.
@3lvis , Sorry for bombarding you with questions haha. And no worries!
-
The way I'm configuring biographyfields are like below:
for item in self.BiographyCustomFieldArray {
if field.type == .Custom && field.typeString == item {
BiographyCustomField.CellIdentifier = item
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(item, forIndexPath:
indexPath) as! BiographyCustomField
cell.biographyFieldDelegate = self
return cell
}
In BiographyCustomField, I have static var CellIdentifier:
class BiographyCustomField: FORMBaseFieldCell {
static var CellIdentifier: String!
}
In the class, I configured delegate like below:
extension BiographyCustomField: UITextViewDelegate {
func textViewDidChange(textView: UITextView) {
self.biographyFieldDelegate?.biographyFieldWasUpdated(textView.text, cellIdentifier: BiographyCustomField.CellIdentifier)
}
}
extension PartConfigurationViewController: BiographyFieldDelegate {
func biographyFieldWasUpdated(text: String, cellIdentifier: String) {
print([cellIdentifier : text])
}
}
The problem I'm seeing is that even if I write values in 3 different biography custom fields, the app thinks I'm writing in one field. For example, let's say there are bio1, bio2, bio3 fields and I input different values. Then it should return like below:
[bio1: 111]
[bio2: 222]
[bio3: 333]
In reality, I get following. You can see the id is not changing but value is chaning.
[bio3: 111]
[bio3: 222]
[bio3: 333]
Can you guess why?
(2)Regards the method (- (FORMSection *)sectionWithID:(NSString *)sectionID;), can you give me an example? I could not figure out where to call this function.
@RyanKim01 2) self.dataSource.sectionWithID("section-id")