« Modular XSLT, part 2: Simple export | Main | Soundex sample »

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d8341d284e53ef00d83463220469e2

Listed below are links to weblogs that reference Linked fields:

» Linked Fields from Secret Weapon Labs
Mikhail Edoshin has posted a great technique on his FileMaker blog (Bits Pieces) on how to create “linked” fields that are directly editable and update each other to keep them in sync (using v7+ auto-enter capabilities is the trick). His id... [Read More]

Comments

David Graham

Are you using a text editor with a FileMaker dictionary or do you manually indent and colorize your code snippets?

m.edoshin

I use SubEthaEdit with a hand-made FileMaker mode. Same for XSLT samples. SEE has a nice option to copy text with highlighted syntax as XHTML. I can share these modes, if someone needs them :)

David Graham

I've long dreamed of the day that we will have a fully functional code-writing engine in FileMaker. With your FileMaker mode does it offer the range of features one would expect (e.g., indenting, bracket matching, autocomplete, functions pop-up)?

m.edoshin

Not quite. The editor is relatively simple so it matches brackets and has an auto-complete feature, which I have never used, but doesn't offer anything else. I don't use it to write FileMaker formulas, only to highlight the syntax before adding snippets to the blog, because this looks nice. You can see the mode isn't quite correct; for example, in one of the snippets it highlights the Position field because it misinterprets it for the Position() function.

I use the editor and my XSLT mode to write XSLT.

Emile

Mikhail,

This is a tremendously useful technique, though I have two questions:

If you wanted to include the start field in your initial example, because a user may actually change the start value once they read the duration, how would you go about doing so?

And secondly, what exactly is FM doing when it reads:
changed = Get( ActiveFieldName ) = "End"

I understand that you are setting changed to GetActive... but then what happens in the rest? Are you setting changed to "end"? Why not just put changed = "End" ??

Cheers!

m.edoshin

Start field is already included, i.e. the other two fields "know" about it and update when it changes. It doesn't have any auto-enter formula because there's no situation (in these samples) when it may be updated automatically. We can put a dummy calculation there like:

Let( changed = Get( ActiveFieldName ) = "Start";
If( changed, Start,
Start ) )

i.e. if the field is changed, then use the new value, if it isn't use the old value, but since the result in both cases is Start such a complex formula is not necessary.

When FM reads the line

changed = Get( ActiveFieldName ) = "End"

it evaluates it in the following manner:

variable = expression

where variable is "changed" and expression is Get( ActiveFieldName ) = "End". This is a boolean expression and it may evaluate to True or False, which are represented as 1 and 0. You can see that later it's used in this logical sense:

If( changed, "true-expression", "false-expression" )

If we set it to simply:

changed = "End"

the formula will be valid, but it won't work as we need it to, because in this case the "expression" will always be same and we'll have no way to see which field is active.

Alexander Zueiv

Good job! The only confusing thing is hardcoded field names - Get( ActiveFieldName ) = "End"... Here is how you can get rid of it using global variables:

End (auto-enter calc, replace existing) =
If ( $$_DURATION_HAS_BEEN_ENTERED ;
Let ( $$_DURATION_HAS_BEEN_ENTERED = "" ; Start + Duration ) ;
Let ( $$_END_HAS_BEEN_ENTERED = 1 ; End )
)

Duration (auto-enter calc, replace existing) =
If ( $$_END_HAS_BEEN_ENTERED ;
Let ( $$_END_HAS_BEEN_ENTERED = "" ; End - Start ) ;
Let ( $$_DURATION_HAS_BEEN_ENTERED = 1 ; Duration )
)

The trick is that FMP first calculates manually modified field.

Enjoy!

Alex_Z

m.edoshin

Thanks, Alex, this is more elegant :) Besides, it makes it possible to write different scenarios depending on which field has changed.

Serge Lavigne

Hi Mikhail
I like your "Link Fields", a very interesting approach. I prefer not using a variable. So I rerote the formula in your example.....

//Let( changed = Get( ActiveFieldName ) = "Duration";
// If( changed; Duration; End - Start ) )
If (Get(ActiveFieldName) = "Duration" ; Duration ; End - Start)

It is a bit simpler to understand for a newby.

Regards

Serge

m.edoshin

Yes, this is simpler; I probably should start with this and then show how to use a variable. Thanks :)

Matt Petrowsky

Very cool Mikhail! Yet another clear presentation of some great coding. I'm always amazed when I see your stuff and have to hit myself in the forehead, saying "Oh, duh, you've done that in PHP or Perl, why not FileMaker!"

I'm referring to the order of operations regarding the assignment of the changed variable. Yes, a bit difficult for a newbie to understand, but it makes perfect sense! Thanks again for a great tip. If you don't mind, I'll have to give my viewers a sneak peek into this great idea.

m.edoshin

Thanks Matt! Sure, I don't mind; I'm happy you're going to tell your readers about this tip. This means I'm among the best :)

Guy

Cool indeed. It helped me solve some problems that desperately needed this. Strange though that it doesn't seem to work with container fields(?), e.g. to create true drag and drop (source field emptying itself). I thought I had it working for a few tries, but then I could never get it to work again... Anyway, a big thanks to all! :-)

penis enlargement

In short, your penis will go through a natural penis enlargement process. ... Engineered as a one stop solution for your natural penis enlargement needs

vimax

We have been selling Vimax penis enlargement pills for over 6 years and have a 95% success rate. VIMAX is a natural herbal formula for penis enlargement ...

art paintings

I really enjoyed the great benefit of your article concerning the matter as I'm totally new in this field. Thank you for posting this. I have bookmarked it and will come back for more useful information.

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment