Fitlering Lookup

Thank you for the Cascading lookup option. I was wondering if we could use this to filter by a Choice field?
So that if a user selections a value in a choice filed it would filter the lookup?
Could this be done by retrieving the Value instead of the Id?
We have a lot of InfoPath forms we are trying to convert over and many of them use “Data Connections” to a single line of text instead of lookups.

Dear Jennifer,
Yes, it is possible to do with Choice field. Lookups use OData $filter query and you can use any values with it. Make sure to add the field that you want to use for filtering as an Extra field in Lookup properties, if it’s not the field that Lookup displays by default.

Your code could look kind of like this:

fd.spRendered(function() {
    function filterLookup(v){
        // getting the selected Choice (0 if nothing is selected).
        var choice = v;

        // setting filtration
        fd.field('Lookup').filter = "FieldName eq '" + choice + "'";


    //filter when form opens

    //filter when Choice changes
    fd.field('Choice').$on('change', function(value){
        fd.field('Lookup').value = null;

Thank you for the quick response this worked great.
I have one other filtering item I have a date field in my lookup called StartDate
I know I can get it in the Extra Fields
but I would like to also filter by it so that the items do not show more then any items that
had a Start Date of Today-21 days
something like
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -21);
Date dateBefore30Days = cal.getTime();
I want to use that date to the StartDate to filter out anything older then 21 days.

Dear Jennifer,
Please, try the following code:

fd.spRendered(function() {
    function filterLookup(){
        //today's date:
        var today = new Date();
        //number of ms in a day:
        var day = 86400000;
        //amount of days:
        var amountOfDays = 21;
        //get date to filter with:
        var filterValue = today - (day * amountOfDays);
        var filterDate = new Date(filterValue);

        // setting filtration
        fd.field('Lookup').filter = "StartDate gt datetime'" + filterDate.toISOString() + "'";


    //filter when form opens