Not able to display required message properly when tried using custom javascript for dynamic table f

soundar rajasoundar raja Member
edited March 2017 in Problems
image
Please find the javascript which is used to display different fields as required in the same column in the table based on the Data type picklist value field and when we tried to save it is throwing error message but its not displaying the field label .
 
Error Message: "Required Fields have no Value [undefined]"

var $ = skuid.$,    model = arguments[0].model,
    list = arguments[0].item.list ,
item=arguments[0].item,
row=arguments[0].row,
    element = arguments[0].element;

console.log('arguments[0] '+arguments);
var valueType = model.getFieldValue( row , 'Data_Type__c' );
console.log('repeating');

list.addRequiredField({ id: 'Number_Draft_Value__c' });

console.log();
function renderField( fieldName,defaultValue ){
    
    var field = new skuid.ui.Field( row, model, null, { fieldId: fieldName, register: true, mode: 'edit' } ),
        value = model.getFieldValue( row , fieldName ) ||defaultValue;
        console.log( field, value );

        if(field && field.metadata && field.metadata.displaytype ){
            //skuid.ui.fieldRenderers[field.metadata.displaytype][field.mode]( field, value );
            console.log( fieldName + ' rendered!', field.element );
            skuid.ui.fieldRenderers[field.metadata.displaytype].edit( field, value );
        }
field.required=true;
field.render();
    return field.element;
}

switch ( valueType ){
    case 'Extended Amount':
         element.append(
            $('<span>').text(' Qty: '),
            
            renderField( 'Quantity_Draft__c' ,''),
            $('<span>').text(' Unit: '),

            renderField( 'Unit_Draft__c','' ),
            $('<span>').text(' Rate: '),

            renderField( 'Rate_Draft__c','' ),
            $('<span>').text(' Total: '),

            renderField( 'Total_DRAFT__c' ,'') );
        break;
    case 'Date':
         element.append( //$('<span>').text(' Date Value '),
         renderField( 'Date_Draft_Value__c' ,''));

        break;
    
}

Answers

  • J.J. Skuad ✭✭
    edited March 2017
    Hi, Soundar. I think you need to send some additional metadata into the list.addRequiredField function. You can use skuid.model.Model.getField to get the full Salesforce field metadata as a JavaScript object. Assuming that the Number_Draft_Value__c field is in the model being passed to that snippet, try something like this:
    var fieldMetadata = model.getField('Number_Draft_Value__c');  list.addRequiredField(fieldMetadata);
  • Rob HatchRob Hatch Skuad ✭✭
    edited September 2016
    Nothing jumps out at me here as obviously wrong.  You are using all the standard API methods that I would expect to do the field rendering as appropriate.  I believe where things are going south is on your model save action (which is more of a core skuid thing). 

    I'd encourage you to more thoroughly investigate the model after you have made changes to see if all the fields have names,  to see what the requiredness value is set to,  to see whether the changes node is populated with what you would expect etc. 

    We can't exactly reproduce your issue here because of all the customization in your code and metadata,  but you should be able to debug this. 
Sign In or Register to comment.