protected override FieldDefinition GetFieldDefinitionTemplate()
        {
            var def = new LookupFieldDefinition();

            def.AllowMultipleValues = Rnd.Bool();

            return def;
        }
        public void LookupFieldDefinition_AllowMultipleValues_ShouldUpdate_FieldType()
        {
            var def = new LookupFieldDefinition();

            def.AllowMultipleValues = true;
            Assert.IsTrue(def.FieldType == BuiltInFieldTypes.LookupMulti);

            def.AllowMultipleValues = false;
            Assert.IsTrue(def.FieldType == BuiltInFieldTypes.Lookup);
        }
        public Web GetTargetWeb(Site site, LookupFieldDefinition definition)
        {
            var context = site.Context;

            if (definition.LookupWebId.HasGuidValue())
            {
                var targetWeb = site.OpenWebById(definition.LookupWebId.Value);

                context.Load(targetWeb);
                context.ExecuteQueryWithTrace();

                return targetWeb;
            }
            else if (!string.IsNullOrEmpty(definition.LookupWebUrl))
            {
                var targetWebUrl = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
                {
                    Value = definition.LookupWebUrl,
                    Context = context
                }).Value;

                // server relative url, ensure / in the beginning
                targetWebUrl = UrlUtility.RemoveStartingSlash(targetWebUrl);
                targetWebUrl = "/" + targetWebUrl;

                var targetWeb = site.OpenWeb(targetWebUrl);

                context.Load(targetWeb);
                context.ExecuteQueryWithTrace();

                return targetWeb;
            }

            // root web by default
            return site.RootWeb;
        }
 public Web GetTargetWeb(Site site, LookupFieldDefinition definition)
 {
     return GetTargetWeb(site, definition.LookupWebUrl, definition.LookupWebId);
 }
 public static ModelNode AddLookupField(this ModelNode model, LookupFieldDefinition definition, Action<ModelNode> action)
 {
     return model.AddDefinitionNode(definition, action);
 }
 public static ModelNode AddLookupField(this ModelNode model, LookupFieldDefinition definition)
 {
     return AddLookupField(model, definition, null);
 }