1- import { setupBind , Config } from "@ideal-postcodes/jsutil" ;
1+ import { getParent , Config } from "@ideal-postcodes/jsutil" ;
22
33import { setupAutocomplete , setupPostcodeLookup } from "./extension" ;
44
@@ -7,22 +7,18 @@ export const selectors = {
77 line_2 : '[name="address_2"]' ,
88 postcode : '[name="postcode"]' ,
99 post_town : '[name="city"]' ,
10- organisation : '[name="company"]' ,
10+ organisation_name : '[name="company"]' ,
1111 county : '[name="zone_id"]' ,
1212 country : '[name="country_id"]' ,
1313} ;
1414
15- const bind = ( config : Config ) => {
16- setupBind ( {
17- selectors,
18- parentScope : "fieldset" ,
19- parentTest : ( e ) => e . id === "address" ,
20- } ) . forEach ( ( { targets } ) => {
21- setupAutocomplete ( config , targets ) ;
22- setupPostcodeLookup ( config , targets ) ;
23- } ) ;
24- } ;
15+ const getScope = ( anchor : any ) => getParent ( anchor , "fieldset" , ( e ) => e . id === "address" ) ;
2516
2617export const pageTest = ( ) => window . location . href . includes ( "/checkout" ) ;
2718
28- export const bindings = { bind, pageTest } ;
19+ const bind = ( config : Config ) => {
20+ setupAutocomplete ( config , selectors , pageTest , getScope ) ;
21+ setupPostcodeLookup ( config , selectors , pageTest , getScope ) ;
22+ } ;
23+
24+ export const bindings = { bind } ;
0 commit comments